| [reply] [d/l] [select] |
jeanluca:
Just to elaborate on the previous response a little bit: Some machines want the Most Significant Byte (MSB) of a word first in memory, while others want the Least Significant Byte (LSB) of a word to be first in memory. "Network Order" is a portable format that was (I think) specified in the TCP/IP RFCs so that machines of both endianness' could interoperate.
If you use network order in your binary formats, then you can make your code interoperable with other platforms. (Amusing note: Network order just happens to be the opposite byte order of the natural x86 order. So there's an incredible amount of time spent on x86 machines swapping byte orders to chat over networks. As there are more x86 machines out there than anything else, I wonder how many cycles are spent on it. But the people who worked on the original networking stuff apparently used boxes based on other CPU architectures than x86 (such as 3B2, 68000, 32032, etc.) so they got to choose!)
...roboticus
| [reply] |
| [reply] [d/l] [select] |
Thanks, BrowserUk. Two years later and that remains to be some very helpful information.
| [reply] |
I have to add the I've always worked with ASCII strings, so pack and unpack are still magic for me, but I'll keep trying!
No I've tried to unpack the following header:
Position(bytes) Datatype
0 - 7 long
8 - 15 long
16 - 23 long
24 - 31 long
32 - 39 long
40 - 43 int
44 - 51 long
I checked with 'od -l' (on a Unix system):0000000 0 2000 0 200
0000020 0 455800 0 4
0000040 0 8 2000 275
0000060 281946600 167772160
0000065
I only know that the 6th value is 2000, which is now the 11th value, so I get the impression that it is expected that a long is only 4 bytes, does that make any sense ?
Now, when I do (on Linux)my @vals = unpack("N*", $binrec ) ;
print "@vals" ;
Output
0 2000 0 200 0 455800 0 4 0 8 2000 275 281946600
I get the same values as od except for the last value!
The last thing that confuses me is how to convert a singed/unsiged integer from big to little endian ?
LuCa
| [reply] [d/l] [select] |