Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!wuarchive!udel!haven!uvaarpa!murdoch!astsun.astro.Virginia.EDU!jvb7u From: jvb7u@astsun.astro.Virginia.EDU (Jon Brinkmann) Newsgroups: comp.lang.c Subject: Re: How to reverse bits... Message-ID: <1990Aug24.224527.10863@murdoch.acc.Virginia.EDU> Date: 24 Aug 90 22:45:27 GMT References: <9008241924.AA00274@bisco.kodak.COM> Sender: news@murdoch.acc.Virginia.EDU Organization: University of Virginia Lines: 29 In article <9008241924.AA00274@bisco.kodak.COM> nobody@Kodak.COM 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 ? # # I am looking at doing just this! We are working on Sun 3/80 systems and #porting to a Sparc station. In the process, we are thinking of what might #happen if we wanted to go to some other system (read that, "IBM") which uses #the "wrong" byte order. The sender isn't talking about BYTE order, he's talking about BIT order. They are obviously NOT the same! Byte order is trivially handled on most machines. There was an extensive discussion in this newsgroup about a year ago. Check the archives. Now about bit order. Most processors don't handle bits individually. You'll have to check each bit in the source and set the appropriate bit in the destination. Something like for (i = dest = 0, j = 1; i < 8; i++, j << 1) if (source & j) dest |= 1 << (7 - i); Jon --- -- Jon Brinkmann Astronomy Department Internet: jvb7u@Virginia.EDU University of Virginia UUCP: ...!uunet!virginia!jvb7u P.O. Box 3818 SPAN/HEPnet: 6654::jvb7u Charlottesville, VA 22903-0818