Actually, I don't need to know this, but here is the code for detecting endianness for normal big and little 32bit machines. Extensions for 64bit welcome; but this works for me on Linux-IA32 and Solaris2.6-UltraSparc .
@b = unpack('CCCC', pack('I', 0x04030201)); if ($b[0] == 4 and $b[1] == 3 and $b[2] == 2 and $b[3] == 1 ) { print "big-endian\n"; } elsif ($b[0] == 1 and $b[1] == 2 and $b[2] == 3 and $b[3] == 4 ) { print "little-endian\n"; } else { print "funky-endian\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(tye)Re: Detecting machine Endian-ness
by tye (Sage) on Aug 06, 2001 at 23:24 UTC | |
by LunaticLeo (Scribe) on Aug 07, 2001 at 02:58 UTC | |
by tye (Sage) on Aug 07, 2001 at 07:48 UTC | |
|
Re: Detecting machine Endian-ness
by jmcnamara (Monsignor) on Aug 07, 2001 at 15:26 UTC |