42

On my machine I get the following output when I run these commands:

$ echo foos > myfile
$ hexdump myfile
6f66 736f 000a

The output from hexdump is little-endian. Does this mean that my machine is little-endian, or does hexdump always use little-endian format?

0

2 Answers 2

56

The traditional BSD hexdump utility uses the platform's endianness, so the output you see means your machine is little-endian.

Use hexdump -C (or od -t x1) to get consistent byte-by-byte output irrespective of the platform's endianness.

1
5

From the manpage:

 -x      Two-byte hexadecimal display.  Display the input offset in hexa‐
         decimal, followed by eight, space separated, four column, zero-
         filled, two-byte quantities of input data, in hexadecimal, per
         line.

...

 If no format strings are specified, the default display is equivalent to
 specifying the -x option.

Your output is little-endian (least significant byte first), which is also the endianness of the x86 and x86_64 architectures, which you are probably using.

4
  • 4
    Is it just me, or does the man page not mention anywhere that it is treating the "two-byte quantities" as integers? I thought I was taking crazy pills... Jun 14, 2017 at 21:41
  • @slashingweapon "two-byte quantity of input data" is uint16_t integer.
    – Ruslan
    May 8, 2018 at 7:53
  • 2
    "Two bytes" is not the same as uint16_t on a little-endian system. May 10, 2018 at 16:43
  • Furthermore, we should stop using this ambiguous term called "byte". If you meant 8-bit units, then "octet" would be precise.
    – ZeZNiQ
    Jan 2 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.