Path: utzoo!attcan!uunet!mailrus!usenet.ins.cwru.edu!abvax!iccgcc!browns From: browns@astro.pc.ab.com (Stan Brown, Oak Road Systems) Newsgroups: comp.lang.c Subject: Re: How to reverse bits... Message-ID: <464.26c93018@astro.pc.ab.com> Date: 15 Aug 90 16:20:56 GMT References: <2059@ux.acs.umn.edu> <1990Aug14.203212.16248@motcad.portal.com> <1990Aug14.233308.27889@caen.engin.umich.edu> Lines: 28 In article <1990Aug14.233308.27889@caen.engin.umich.edu>, jal@acc (John Lauro) writes: > 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; > > - John_Lauro@ub.cc.umich.edu Please, no magic numbers. You can use the bitwise-complement operator, ~ tilde (pronounced, "squiggle"). c = ~c It works on any numeric type, and the result has the same type as the operand. Typical application: to sset all the bits in n unsigned word: unsigned all_bits_set = ~(unsigned)0; -- Stan Brown, Oak Road Systems, (216) 371-0043 The opinions expressed are mine. Mine alone! Nobody else is responsible for them or even endorses them--except my cat Dexter, and he signed the power of attorney only under my threat to cut off his Cat Chow!