Reputation: 1633
Here's the output dumped from od -cx
(on linux you can reproduce with echo -ne "\r\n\n" |od -cx
):
0000000 \r \n \n \0
0a0d 000a
0000003
The correct first 2 bytes should be 0d0a
but it outputs 0a0d
,why?
Upvotes: 2
Views: 129
Reputation: 31579
Because it's reading it as shorts and not as bytes. Short is 2 bytes reversed.
Upvotes: 0
Reputation: 4244
Because your computer is using the so-called "little-endian" method to represent words in the memory (the x86 processor architecture is a common example of little endian systems).
Upvotes: 0
Reputation: 38442
because you're on a little-endian system? a 16-bit integer will be the high byte followed by the low byte; in this case the 2nd byte followed by the first.
Upvotes: 4