hexdump 是否尊重其系统的字节序?

Cor*_*ein 34 bsd utilities hexdump

在我的机器上,当我运行这些命令时,我得到以下输出:

$ echo foos > myfile
$ hexdump myfile
6f66 736f 000a
Run Code Online (Sandbox Code Playgroud)

hexdump 的输出是小端的。这是否意味着我的机器是小端格式,还是 hexdump 总是使用小端格式?

Gil*_*il' 47

传统的 BSDhexdump实用程序使用平台的字节序,因此您看到的输出意味着您的机器是小字节序的。

使用hexdump -C(或od -t x1) 获得一致的逐字节输出,而不管平台的字节序如何。


Den*_*ker 5

从联机帮助页:

 -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.
Run Code Online (Sandbox Code Playgroud)

...

 If no format strings are specified, the default display is equivalent to
 specifying the -x option.
Run Code Online (Sandbox Code Playgroud)

您的输出是 little-endian(最低有效字节在前),这也是您可能正在使用的 x86 和 x86_64 架构的字节序。

  • 只是我,还是手册页没有提到将“两字节数量”视为整数的任何地方?我以为我在吃疯狂的药... (3认同)
  • “两个字节”与小端系统上的 uint16_t 不同。 (3认同)