in reply to (tye)Re: Detecting machine Endian-ness
in thread Detecting machine Endian-ness
Note that the "I" format can result in more than 4 bytes on some platforms.
Yeah, I suppose you could use 'L' then.
I suppose you could figure out the size of integers with code like:
@b = unpack('C*', pack('I', 0)); return scalar(@b);
Then you could make the endian code more generic with:
@b = unpack('C*', pack('I', 0)); $sizeof_long = scalar(@b); @c = (1..$sizeof_long); $i = pack('I', hex('0x0'.join('0',reverse @c))); $big = pack('C'.$sizeof_long, reverse @c); $lit = pack('C'.$sizeof_long, @); if ( substr($i, 0, $sizeof_long) eq $big ) { return 'big'; } elsif ( substr($i, 0, $sizeof_long) eq $lit ) { return 'little'; } else { return "strange"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(tye)Re2: Detecting machine Endian-ness
by tye (Sage) on Aug 07, 2001 at 07:48 UTC |