Newsgroups: comp.lang.c
Path: utzoo!telly!robohack!druid!darcy
From: darcy@druid.uucp (D'Arcy J.M. Cain)
Subject: Re: How to reverse bits...
Message-ID: <1990Aug14.171821.3932@druid.uucp>
Organization: D'Arcy Cain Consulting, West Hill, Ontario
References: <1990Aug13.222454.3862@craycos.com>
Date: Tue, 14 Aug 90 17:18:21 GMT

In article <1990Aug13.222454.3862@craycos.com> pmk@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@druid)     |
D'Arcy Cain Consulting             |   MS-DOS:  The Andrew Dice Clay
West Hill, Ontario, Canada         |   of operating systems.
+ 416 281 6094                     |
