[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Big-endian/little-endian (WAS: Re: can I burn the output of mpg123 -s?)



On Tue, Aug 18, 1998 at 02:03:11PM +0200, Wojciech Zabolotny wrote:
> Hi!
> 
> Some of my programs have to work on big-endian and little-endian systems,
> knowing what kind of system they are runing on (they are exchanging data
> in binary format). To recognize the kind of the system I use the following
> routine:

cool....
xfstt is lgpl'd...I dunno about the programs you use....
you mind if I use your code in it? 
(btw its a very nice aproach...its sort of how I suggested swapping the
byte order when discussing the problem with the author once)

I don't know if this code is NEEDED in fact... xfstt already detects if there
is a byteorder DIFFERECE between the hosts but AFAIK (read: I didn't look
THAT closely at it yet) I don't think it detects what type each
end is...
I think that wouldn't be needed tho... as long as a difference exists...
all the swaps are the same...I think I can get away by just performing
the right swaps if a global "endiandifference" flag is set without
knowing what it is...
alternarely...without a uninon...
as for the swap...
The authors concern was that on a big endian system network order and
byte order are the same so hton* and ntoh* do nothing....so how do you
do the swapps...
I suggested a union first (like below) but...whats the "proper" way of
doing it? 
Th ebest I can figure...you would set the value...and copy it to a temp
variable...
then bitwise AND the original against 11110000 and the 
copy against 00001111 then perform a left shift on one...a right shift on 
the other...and XOR them back together...
(NB: the number of 111 and 000 may be wrong...I am writting this off the
top of my head ;) ...its just to illistrate the idea )

is this sound right (I forget my real proposed code...I actually
wrote the code in the e-mail to him)?
 
-Steve
-- 
/* -- Stephen Carpenter <sjc@delphi.com> --- <sjc@debian.org>------------ */
E-mail "Bumper Stickers":
"A FREE America or a Drug-Free America: You can't have both!"
"honk if you Love Linux"


Reply to: