Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!usc!apple!portal!motcad!jtc From: jtc@motcad.portal.com (J.T. Conklin) Newsgroups: comp.lang.c Subject: Re: How to reverse bits... Message-ID: <1990Aug14.203212.16248@motcad.portal.com> Date: 14 Aug 90 20:32:12 GMT References: <2059@ux.acs.umn.edu> Organization: CADnet Inc., San Ramon CA Lines: 28 In article <2059@ux.acs.umn.edu> dhoyt@vw.acs.umn.edu writes: >In article <1990Aug13.185757.3236@sti.fi>, ttl@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@motcad.portal.com, ...!portal!motcad!jtc