in reply to sprintf %X endianness
If you know the raw data is little-endian, you can convert it to the current local endianness (without knowing what that is) using:
my $raw = "\x01\x02\x03\x04";; my $local = unpack 'L<', $raw;;
Then you can use it as you would any other local variable:
printf "%08x\n", $local;; 04030201
Ditto, if you know the raw bytes are big-endian:
my $raw = "\x01\x02\x03\x04";; my $local = unpack 'L>', $raw;;
And now when your print it:
printf "%08x\n", $local;; 01020304
The point is that once you've done the unpack, it will have been converted to the local format and from that point on you need not consider the endianess; just use it and the code will do the right thing.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: sprintf %X endianness
by Anonymous Monk on May 14, 2013 at 19:58 UTC | |
by SuicideJunkie (Vicar) on May 14, 2013 at 21:06 UTC | |
by Anonymous Monk on May 14, 2013 at 21:15 UTC | |
by BrowserUk (Patriarch) on May 14, 2013 at 21:50 UTC | |
by Anonymous Monk on May 14, 2013 at 22:46 UTC | |
by BrowserUk (Patriarch) on May 14, 2013 at 23:23 UTC | |
by Anonymous Monk on May 15, 2013 at 02:01 UTC | |
|