How to reverse bits...

J.T. Conklin jtc at motcad.portal.com
Wed Aug 15 06:32:12 AEST 1990


In article <2059 at ux.acs.umn.edu> dhoyt at vw.acs.umn.edu writes:
>In article <1990Aug13.185757.3236 at sti.fi>, ttl at sti.fi (Timo Lehtinen) writes...
>>This might be trivial, but here goes...
>>What's the most optimal way to reverse the bits in an unsigned char,
>>i.e. change from MSB to LSB ordering ?
>
>  You don't have to change anything.  Big and little endians only cause
>trouble when you look at different integer formats.  Bytes is bytes, as they
>say.

The question was how to flip the bits in an unsigned char, not a bytes
in a word.  Like has been indicated in previous postings, a 256 element
lookup table is the best way to perform this task.

For example, most fax machines/modems present the bits in lsb-to-msb bit
order.  If your G3 decompression code was written for msb-to-lsb order,
bit reversal is needed.

Another useful table is one that flips the bits 1-for-0,0-for-1.  This
is useful for inverting an image.

	--jtc

-- 
J.T. Conklin	UniFax Communications, Inc.

		CADnet Inc, San Ramon California
		jtc at motcad.portal.com, ...!portal!motcad!jtc



More information about the Comp.lang.c mailing list