22

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?

29

Yes, the traditional BSD hexdump utility always uses the platform's endianness. Use hexdump -C (or od -t x1) to get more sensible byte-by-byte output.

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.

  • 3
    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... – slashingweapon Jun 14 '17 at 21:41
  • @slashingweapon "two-byte quantity of input data" is uint16_t integer. – Ruslan May 8 '18 at 7:53
  • "Two bytes" is not the same as uint16_t on a little-endian system. – slashingweapon May 10 '18 at 16:43

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.