How to reverse bits...

Charles Tryon bilbo at bisco.kodak.COM
Sat Aug 25 05:24:25 AEST 1990


In message <2059 at ux.acs.umn.edu>,  dhoyt at vw.acs.umn.edu writes
> In article <1990Aug13.185757.3236 at sti.fi>, ttl at 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 at vx.acs.umn.edu | dhoyt at umnacvx.bitnet


--
Chuck Tryon
       (PLEASE use this address, as Kodak foobars one in header!)
    <bilbo at bisco.kodak.com>
    USmail: 46 Post Ave.;Roch. NY 14619                       B. Baggins
                 <<...include standard disclamer...>>         At Your Service

     "Then again, squirrels could be stupid."   (D. Mocsny)



More information about the Comp.lang.c mailing list