Article View: comp.std.c
Article #3686Re: Help: How to determine big/little endian?
From: Stephen Baynes
Date: Wed, 09 Aug 1995 07:22
Date: Wed, 09 Aug 1995 07:22
30 lines
1421 bytes
1421 bytes
Frank DENIS (Jedi/Sector One) (denis_r@epita.fr) wrote:
: You might try something like :
: short a = 0x1234;
:
: if (*((char *) &a + sizeof(short) - 1) == 0x34)
: type = BIG_ENDIAN;
: else
: type = LITTLE_ENDIAN;
Beware of char not being 8 bits!
Beware of mixed big/little for integers of size > 2
Eg a 4 byte integer could store 0x12345678 as any of
12 34 56 78 Big endian
34 12 78 56 !
78 56 43 12 Little endian
56 78 12 34 !
Beware of holes!
Beware of other things that could exist in theory but I have not met in
practice like bit reordering between different types.
--
Stephen Baynes baynes@mulsoc2.serigate.philips.nl
Philips Semiconductors Ltd
Southampton My views are my own.
United Kingdom
Technical Details
Message-ID:
<DD18HI.F7D@ukpsshp1.serigate.philips.nl>Path:
arc1-ca.pugleaf.net!phcoms4.seri.philips.nl!panther!baynesReferences:
<40762c$nh7@masala.cc.uh.edu> <407hp9$mjv@boson.epita.fr>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!phcoms4.seri.philips.nl!panther!baynes From: baynes@ukpsshp1.serigate.philips.nl (Stephen Baynes) Subject: Re: Help: How to determine big/little endian? Sender: news@ukpsshp1.serigate.philips.nl (account for localnews) Message-ID: <DD18HI.F7D@ukpsshp1.serigate.philips.nl> Date: Wed, 9 Aug 1995 07:22:30 GMT References: <40762c$nh7@masala.cc.uh.edu> <407hp9$mjv@boson.epita.fr> Organization: Philips Semiconductors, Southampton, UK X-Newsreader: TIN [version 1.2 PL2]