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

N

NISARG

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....
 
B

Ben Pfaff

NISARG said:
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.
 
V

Vladimir S. Oka

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.
 
J

John Devereux

NISARG said:
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.
 
M

Me

NISARG said:
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).
 
W

wolf0403

it can be done by building a function,,but if there is any single
__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
 
S

slebetman

NISARG said:
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.
 
E

Eric Sosman

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.
 
C

CBFalconer

Eric said:
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/>
 
J

John Devereux

Eric Sosman said:
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? ... :(
 
R

Richard Heathfield

John Devereux said:

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.
 
S

slebetman

John said:
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..
 
E

Eric Sosman

John said:
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 ..."
 
A

Al Balmer

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 ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,176
Messages
2,570,950
Members
47,500
Latest member
ArianneJsb

Latest Threads

Top