2

Using hexdump, printing these characters in the "canonical" format gives the output that I expect, while the default format throws me off.

$ echo " " |hexdump                  # Reversed?
0000000 0a20
0000002

$ echo -n " " |hexdump               # Ok, fair enough.
0000000 0020

$ echo  " " |hexdump -C              # Canonical
00000000  20 0a                      | .|
00000002

With a different string, such as "123", the output is even more confusing:

$ echo  "123" |hexdump
0000000 3231 0a33
0000004

The output here does not seem "reversed", but rather it is shuffled. What (briefly) is going on here?

Peter Mortensen
  • 12,090
  • 23
  • 70
  • 90
  • This looks like a tool the Git authors worked on. It takes a simple task, and makes it difficult... – jww Jun 30 '16 at 16:46

1 Answers1

1

The default format is 16-bit little-endian unsigned ints.

The manual page of hexdump explains the default format as well:

 -x  Two-byte hexadecimal display.  Display the input offset in hexadecimal, 
     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.
Nicole Hamilton
  • 9,935
  • 1
  • 21
  • 43