468,510 Members | 1,482 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,510 developers. It's quick & easy.

How to reverse a Unsigned Char??

I have a unsigned char.. i need to reverse it.. what the easiest way to
do it?? i dont want to tap each bit save and restore etc etc....

Is it possible to perform some bitwise operation which will give the
reversed char.

e.g., unsigned char x = 0x8A
am expecting an output after reversal x = 0x51

Oct 24 '06 #1
4 5713

ra*******@gmail.com wrote:
I have a unsigned char.. i need to reverse it.. what the easiest way to
do it?? i dont want to tap each bit save and restore etc etc....

Is it possible to perform some bitwise operation which will give the
reversed char.
Go to Google Groups and search for "reverse" in comp.lang.c

Oct 24 '06 #2
ra*******@gmail.com wrote:
I have a unsigned char.. i need to reverse it.. what the easiest way to
do it?? i dont want to tap each bit save and restore etc etc....
Is it possible to perform some bitwise operation which will give the
reversed char.
e.g., unsigned char x = 0x8A
am expecting an output after reversal x = 0x51
There's no operator or standard function for this in C, but if you
google for 'reverse bits in a byte' you will find e.g.

http://graphics.stanford.edu/~seande...ReverseObvious

and lots of other results.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
Oct 24 '06 #3
2006-10-24 <11**********************@e3g2000cwe.googlegroups. com>,
ra*******@gmail.com wrote:
I have a unsigned char.. i need to reverse it.. what the easiest way to
do it?? i dont want to tap each bit save and restore etc etc....

Is it possible to perform some bitwise operation which will give the
reversed char.

e.g., unsigned char x = 0x8A
am expecting an output after reversal x = 0x51
static unsigned char CSStab4[256]=

{
0x00,0x80,0x40,0xc0,0x20,0xa0,0x60,0xe0,
0x10,0x90,0x50,0xd0,0x30,0xb0,0x70,0xf0,
....
And so on in much the same manner.

x = 0x8a;
x[CSStab4] == 0x51;
Oct 24 '06 #4
ra*******@gmail.com wrote:
>
I have a unsigned char.. i need to reverse it.. what the easiest way to
do it?? i dont want to tap each bit save and restore etc etc....

Is it possible to perform some bitwise operation which will give the
reversed char.

e.g., unsigned char x = 0x8A
am expecting an output after reversal x = 0x51
unsigned char bit_rev(unsigned char byte)
{
unsigned hi_mask = ((unsigned char)-1 >1) + 1;
unsigned lo_mask = 1;

do {
if (!(byte & hi_mask) != !(byte & lo_mask)) {
byte ^= hi_mask | lo_mask;
}
hi_mask >>= 1;
lo_mask <<= 1;
} while (hi_mask lo_mask);
return byte;
}

--
pete
Oct 24 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

47 posts views Thread by Kapil Khosla | last post: by
6 posts views Thread by John Deuf | last post: by
20 posts views Thread by sahukar praveen | last post: by
10 posts views Thread by Tomás | last post: by
47 posts views Thread by sudharsan | last post: by
20 posts views Thread by mike7411 | last post: by
11 posts views Thread by lovecreatesbea... | last post: by
40 posts views Thread by KG | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.