Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!ucbvax!bisco.kodak.COM!bilbo From: bilbo@bisco.kodak.COM (Charles Tryon) Newsgroups: comp.lang.c Subject: Re: How to reverse bits... Message-ID: <9008241924.AA00274@bisco.kodak.COM> Date: 24 Aug 90 19:24:25 GMT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: nobody@Kodak.COM Organization: Eastman Kodak Company; Rochester, NY Lines: 43 In message <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. > > Everyone thinks that 2^128 is 10000000. The trouble arises with characters > packed into integers. Everyone knows that in 'abcd' 'a' is the first > character. But if packed into an integer on a dec, intel or national semi > machine the string would read 'dcba.' That is the first letter, 'a', will be > in the Least Significant BYTE. Most others would say the integer would look > like 'abcd.' The first character is the Most Significant BYTE. ..(stuff deleted).. > unions, you shouldn't ever have problems. > > Except when you do binary ftp's or swap binary (not character!) data with > machines on the wild side. 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. Sun has a package called XDR (for eXternal Data Representation) which I am looking at. Are there any other portability "standards" that people out there have seen/used which might be more widely accepted for this sort of thing? > david paul hoyt | dhoyt@vx.acs.umn.edu | dhoyt@umnacvx.bitnet -- Chuck Tryon (PLEASE use this address, as Kodak foobars one in header!) USmail: 46 Post Ave.;Roch. NY 14619 B. Baggins <<...include standard disclamer...>> At Your Service "Then again, squirrels could be stupid." (D. Mocsny)