Does hexdump respect the endianness of its system?

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?

Asked By: Cory Klein

||

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.

Answered By: Dennis Kaarsemaker

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.

Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.