Unix History: Why does hexdump default to word alignment?

Unix History: Why does hexdump default to word alignment?

guy keren choo at actcom.co.il
Thu Dec 1 10:26:21 IST 2011


On 12/01/2011 10:10 AM, Nadav Har'El wrote:
> On Thu, Dec 01, 2011, Elazar Leibovich wrote about "Unix History: Why does hexdump default to word alignment?":
>> The default behaviour of hexdump is to align data word-wide. For instance
>
> Just as a comment, if I remember correctly, "hexdump" isn't actually
> part of ancient Unix history - the original was "od", which as its name
> suggests dumps in *octal*, but had an option "od -x" to see hexadecimal.
>
> In any case, od and hexdump are very similar, and apparently have the
> same ideosynchacies, as "od -x" also defaults two two-byte words.
>
>>      printf '\xFF\xFF\x01' | hexdump
>>      0000000 ffff 0001
>>      0000003
>>
>> This makes little sense to me. In C, structs are not necessarily aligned to
>> words, and it doesn't seems useful to view about any data format for which
>> you're sure everything is word-aligned. The "hexdump -C" behaviour makes
>> much more sense in the general case.
>
> When you say "words" and "word aligned" here, you mean historic 2 byte words.
> This is indeed *NOT* a very useful default on any modern computers. In some
> old computers, like the PDP11 2 byte words were common and useful.
> In other old computers, this was never a useful default.
>
> I guess nobody cares because since the 1970s when these tools were
> written, nobody uses them any more ;-) I don't think I used "od" in at
> least two decade... At least since "less" was invented and usually does
> the right thing (show ASCII when possible, or hex for nonvisible
> characters).
>
> Amazingly, I don't believe that the original od even had an option to
> see hex for each byte: "od -c" didn't show hex, "od -x" showed hex for
> each two bytes, and "od -b" (for "bytes") showed each byte but octal
> (which evidentally was more popular than hex in the old days).
>
> Gnu's od can do what you want with "od -t x1". As you saw, so can
> hexdump with the "-C" flag.
>

apparently, you did not use binary data serialization in the past two 
decades. when you serialize data and store it into a file (also on the 
network), it is very useful to be able to see the data as 2-byte or 
4-byte or whatever-byte numbers, when debugging.

in the last few years, i have been using od more then i did in the 
decade before that ;)

--guy



More information about the Linux-il mailing list