How to reverse bits...

D'Arcy J.M. Cain darcy at druid.uucp
Wed Aug 15 03:18:21 AEST 1990


In article <1990Aug13.222454.3862 at craycos.com> pmk at craycos.com (Peter Klausler) writes:
>If the range of your bit-reversal function is limited to chars, use a lookup
>table. If your range is bigger, split your data into bytes and then use a
>lookup.

I believe the original poster meant that he wanted to change endian-ness.
Something like:
#define reverse_word(i)    ((i | (i << 16) >> 8) & 0xffff)

If you are worried about side effects a slightly less efficient way is:
#define reverse_word(i)    (((i * 65537L) >> 8) & 0xffff)

-- 
D'Arcy J.M. Cain (darcy at druid)     |
D'Arcy Cain Consulting             |   MS-DOS:  The Andrew Dice Clay
West Hill, Ontario, Canada         |   of operating systems.
+ 416 281 6094                     |



More information about the Comp.lang.c mailing list