flipping bits (was: Re: How to reverse bits...)
Jan Christiaan van Winkel
jc at atcmp.nl
Wed Aug 15 17:38:08 AEST 1990
>From article <1990Aug14.233308.27889 at caen.engin.umich.edu>, by jal at acc (John Lauro):
) In article <1990Aug14.203212.16248 at motcad.portal.com> jtc at motcad.portal.com (J.T. Conklin) writes:
)>Another useful table is one that flips the bits 1-for-0,0-for-1. This
)>is useful for inverting an image.
)
) How about: (assuming 8 bit char c)
) c=255-c; or
) c^=255;
Why make specifications about the charcter's size in bits? There is an
operator in C that is perfectly suited to do the job without having to specify
the number of bits to be flipped:
c = ~c;
which works for chars, ints, longs, ....
JC
--
___ __ ____________________________________________________________________
|/ \ Jan Christiaan van Winkel Tel: +31 80 566880 jc at atcmp.nl
| AT Computing P.O. Box 1428 6501 BK Nijmegen The Netherlands
__/ \__/ ____________________________________________________________________
More information about the Comp.lang.c
mailing list