473,395 Members | 2,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

is there any instruction or operator to convert a Byte from 10110001 to 10001101?

Hi,
is there any single instruction or operator in 'C' [as Rotate(RL A) in
8051 assembly)] to
convert a byte such that MSB will become LSB and so.....

for example:11101010 will become 01010111

it can be done by building a function,,but if there is any single
instruction than plz tell....

Mar 15 '06 #1
13 2133
On Wednesday 15 March 2006 22:14, NISARG opined (in
<11*********************@j33g2000cwa.googlegroups. com>):
Hi,
is there any single instruction or operator in 'C' [as Rotate(RL A)
in
8051 assembly)] to
convert a byte such that MSB will become LSB and so.....

for example:11101010 will become 01010111

it can be done by building a function,,but if there is any single
instruction than plz tell....


No, there is no such instruction, but as you say, it's not difficult to
implement as a function or a macro.

--
BR, Vladimir

After an instrument has been assembled,
extra components will be found on the bench.

Mar 15 '06 #2
"NISARG" <ni***********@yahoo.com> writes:
is there any single instruction or operator in 'C' [as Rotate(RL A) in
8051 assembly)] to
convert a byte such that MSB will become LSB and so.....

for example:11101010 will become 01010111


No.
--
"The way I see it, an intelligent person who disagrees with me is
probably the most important person I'll interact with on any given
day."
--Billy Chambless
Mar 15 '06 #3
"NISARG" <ni***********@yahoo.com> writes:
Hi,
is there any single instruction or operator in 'C' [as Rotate(RL A) in
8051 assembly)] to
convert a byte such that MSB will become LSB and so.....

for example:11101010 will become 01010111


This is bit reversal, but your assembly instruction is a
rotation. These are different things, which do you want?

Either way, there is no C operator to do this.

Consider a 256-byte lookup table. Or test & set bits individually.

--

John Devereux
Mar 15 '06 #4
Me
NISARG wrote:
Hi,
is there any single instruction or operator in 'C' [as Rotate(RL A) in
8051 assembly)] to
convert a byte such that MSB will become LSB and so.....

for example:11101010 will become 01010111

it can be done by building a function,,but if there is any single
instruction than plz tell....


No, but many compiler vendors offer intrinsics to rotate (search for
*rotl* in your manual or header files). Otherwise, you can see if your
compiler turns:

inline unsigned char brotl(unsigned char a, unsigned b)
{
return (unsigned)a<<b | (unsigned)a>>CHAR_BIT-b;
}

into a rotate instruction on the proper optimization levels (GCC should
do this).

Mar 16 '06 #5
>> it can be done by building a function,,but if there is any single
instruction than plz tell....


__asm__ ("rorw $8, %w0"
\
: "=r" (__v)
\
: "0" (__x)
\
: "cc");

This is how htonl is implemented in my /usr/include/bite/byteswap.h.
Debian Sarge 3. x86

Mar 16 '06 #6
NISARG wrote:
Hi,
is there any single instruction or operator in 'C' [as Rotate(RL A) in
8051 assembly)] to
convert a byte such that MSB will become LSB and so.....

for example:11101010 will become 01010111

it can be done by building a function,,but if there is any single
instruction than plz tell....


Actually the RL A instruction will not do what you think it does. It
will convert:

11101010 into 11010101

which is the msb removed and appended to the lsb: 1101010 (1). What you
want is something different.

Personally I don't know of any computer ever constructed in the history
of computing that have an instruction that reverses the bits within a
byte/word like what you want. Also I don't know of any programming
language in the history of computing that has built in functions to do
what you want. So you'll have to do it yourself regardless of what
programming language or CPU you use.

Mar 16 '06 #7
sl*******@yahoo.com wrote:

Personally I don't know of any computer ever constructed in the history
of computing that have an instruction that reverses the bits within a
byte/word like what you want. Also I don't know of any programming
language in the history of computing that has built in functions to do
what you want. So you'll have to do it yourself regardless of what
programming language or CPU you use.


Machines with special features to help with Fourier
transforms (digital signal processors and the like) have,
I'm told, addressing modes where array indices are bit-
reversed. Thus, a loop that runs from "0 to 7" would
access elements 0, 4, 2, 6, 1, 5, 3, and 7, in that order.
I don't know whether such machines can deliver the bit-
reversed index as an explicit value, or whether the reversal
remains hidden within the addressing circuitry. Nor do I
know how the capability is usually exposed to programmers.
Nonetheless, the bit-reversal action is certainly present.

The only circumstance I've seen where bit-reversal is
called for is when you're rearranging the transformed values
after the Fast Fourier Transform's "butterfly" steps have
scrambled them (or pre-scrambling the inputs beforehand,
depending on how the FFT is set up). So when someone asks
about bit-reversal I immediately suspect he's doing FFT's --
and if he's doing FFT's, there's at least a chance he's
doing them on a machine with special capabilities, and those
capabilities may even be exposed to C. Not as an integral
part of the language, of course, but as an extension or a
set of extra functions or something of the kind. If it's
there, the O.P. will need to search the documentation for it.

--
Eric Sosman
es*****@acm-dot-org.invalid
Mar 16 '06 #8
Eric Sosman <es*****@acm-dot-org.invalid> writes:
The only circumstance I've seen where bit-reversal is
called for is when you're rearranging the transformed values
after the Fast Fourier Transform's "butterfly" steps have
scrambled them (or pre-scrambling the inputs beforehand,
depending on how the FFT is set up). So when someone asks
about bit-reversal I immediately suspect he's doing FFT's --
and if he's doing FFT's, there's at least a chance he's
doing them on a machine with special capabilities, and those
capabilities may even be exposed to C. Not as an integral
part of the language, of course, but as an extension or a
set of extra functions or something of the kind. If it's
there, the O.P. will need to search the documentation for it.


Bit reversal can also be required when some fool has designed a
circuit board with a piece of hardware wired up wrong, with the data
bus backwards. How do I know this you ask? ... :(

--

John Devereux
Mar 16 '06 #9
John Devereux said:

<snip>
Bit reversal can also be required when some fool has designed a
circuit board with a piece of hardware wired up wrong, with the data
bus backwards. How do I know this you ask?


Ah, what a lovely way to start a new day! Thanks for the chuckle, John.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Mar 16 '06 #10
John Devereux wrote:
Eric Sosman <es*****@acm-dot-org.invalid> writes:
The only circumstance I've seen where bit-reversal is
called for is when you're rearranging the transformed values
after the Fast Fourier Transform's "butterfly" steps have
scrambled them (or pre-scrambling the inputs beforehand,
depending on how the FFT is set up). So when someone asks
about bit-reversal I immediately suspect he's doing FFT's --
and if he's doing FFT's, there's at least a chance he's
doing them on a machine with special capabilities, and those
capabilities may even be exposed to C. Not as an integral
part of the language, of course, but as an extension or a
set of extra functions or something of the kind. If it's
there, the O.P. will need to search the documentation for it.


Bit reversal can also be required when some fool has designed a
circuit board with a piece of hardware wired up wrong, with the data
bus backwards. How do I know this you ask? ... :(


Heh heh.. happened to me once when prototyping. But I simply decided to
de-solder the wires and re-solder them the right war round because bit
reversing code is quite slow. And it was a 32 bit bus..

Mar 16 '06 #11
Eric Sosman wrote:
sl*******@yahoo.com wrote:

Personally I don't know of any computer ever constructed in the
history of computing that have an instruction that reverses the
bits within a byte/word like what you want. Also I don't know of
any programming language in the history of computing that has
built in functions to do what you want. So you'll have to do it
yourself regardless of what programming language or CPU you use.


Machines with special features to help with Fourier
transforms (digital signal processors and the like) have,
I'm told, addressing modes where array indices are bit-
reversed. Thus, a loop that runs from "0 to 7" would
access elements 0, 4, 2, 6, 1, 5, 3, and 7, in that order.
I don't know whether such machines can deliver the bit-
reversed index as an explicit value, or whether the reversal
remains hidden within the addressing circuitry. Nor do I
know how the capability is usually exposed to programmers.
Nonetheless, the bit-reversal action is certainly present.

The only circumstance I've seen where bit-reversal is
called for is when you're rearranging the transformed values
after the Fast Fourier Transform's "butterfly" steps have
scrambled them (or pre-scrambling the inputs beforehand,
depending on how the FFT is set up). So when someone asks
about bit-reversal I immediately suspect he's doing FFT's --
and if he's doing FFT's, there's at least a chance he's
doing them on a machine with special capabilities, and those
capabilities may even be exposed to C. Not as an integral
part of the language, of course, but as an extension or a
set of extra functions or something of the kind. If it's
there, the O.P. will need to search the documentation for it.


Way back when my 8080 based embedded machines provided for it with
a parallel input/output port. All it took was a jumper plug with 8
wires, and some byte swapping software. Turned out I never needed
to do a FFT, and the provision never was used for that.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
Mar 16 '06 #12
John Devereux wrote:
Eric Sosman <es*****@acm-dot-org.invalid> writes:

The only circumstance I've seen where bit-reversal is
called for is when you're rearranging the transformed values
after the Fast Fourier Transform's "butterfly" steps have
scrambled them (or pre-scrambling the inputs beforehand,
depending on how the FFT is set up). So when someone asks
about bit-reversal I immediately suspect he's doing FFT's --
and if he's doing FFT's, there's at least a chance he's
doing them on a machine with special capabilities, and those
capabilities may even be exposed to C. Not as an integral
part of the language, of course, but as an extension or a
set of extra functions or something of the kind. If it's
there, the O.P. will need to search the documentation for it.

Bit reversal can also be required when some fool has designed a
circuit board with a piece of hardware wired up wrong, with the data
bus backwards. How do I know this you ask? ... :(


Ooooohhhhgg!! "Thereby hangs a tale ..."

--
Eric Sosman
es*****@acm-dot-org.invalid
Mar 16 '06 #13
On 15 Mar 2006 14:14:15 -0800, "NISARG" <ni***********@yahoo.com>
wrote:
Hi,
is there any single instruction or operator in 'C' [as Rotate(RL A) in
8051 assembly)] to
convert a byte such that MSB will become LSB and so.....

for example:11101010 will become 01010111

it can be done by building a function,,but if there is any single
instruction than plz tell....


No, there's no single operator.

Your example above is inconsistent with your description. Did you mean
to convert 11101010 to 10101110 ?

--
Al Balmer
Sun City, AZ
Mar 16 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Edward Diener | last post by:
Is there a way to override the default processing of the assignment operator for one's own __value types ? I realize I can program my own Assign method, and provide that for end-users of my class,...
19
by: jeff | last post by:
how do you convert form byte to Int32 while retaining the binary value of the byte array
25
by: Charles Law | last post by:
I thought this was going to be straight forward, given the wealth of conversion functions in .NET, but it is proving more convoluted than imagined. Given the following <code> Dim ba(1) As...
10
by: olson_ord | last post by:
Hi, I am not exactly new to C++, but I have never done operator overloading before. I have some old code that tries to implement a Shift Register - but I cannot seem to get it to work. Here's a...
5
by: Bob Homes | last post by:
In VB6, foreground and background colors of controls had to be assigned a single number. If you knew the RGB values for the color, you still had to convert them into the single number accepatable...
4
by: thorley | last post by:
I'm working with the following code. I included some tests to make it easy to see--if you run the code--what troubles I'm having. Can some one *please* splain me why str(obj) works but not print...
10
by: =?Utf-8?B?RWxlbmE=?= | last post by:
I am surprised to discover that c# automatically converts an integer to a string when concatenating with the "+" operator. I thought c# was supposed to be very strict about types. Doesn't it seem...
8
by: Just another C hacker | last post by:
Hello friends, I'm writing a program in C with some bits in inline asm for efficiency. I'd like to be able to handle illegal instructions from within asm. Here's an example of a standalone asm...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.