wireshark
wireshark

Reputation: 1633

Why od is not ordering bytes correctly?

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

Answers (3)

Daniel
Daniel

Reputation: 31579

Because it's reading it as shorts and not as bytes. Short is 2 bytes reversed.

Upvotes: 0

bandi
bandi

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

jcomeau_ictx
jcomeau_ictx

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

Related Questions