[comp.lang.c] flipping bits

jc@atcmp.nl (Jan Christiaan van Winkel) (08/15/90)

From article <1990Aug14.233308.27889@caen.engin.umich.edu>, by jal@acc (John Lauro):
) In article <1990Aug14.203212.16248@motcad.portal.com> jtc@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@atcmp.nl
   |       AT Computing   P.O. Box 1428   6501 BK Nijmegen    The Netherlands
__/ \__/ ____________________________________________________________________