十六进制转储输出顺序
我正在使用 Unix hexdump 实用程序。我的输入文件是 UTF-8 编码的,包含单个字符 ñ
,即十六进制 UTF-8 中的 C3 B1
。
hexdump test.txt
0000000 b1c3
0000002
啊?这显示了 B1 C3
- 与我的预期相反!有人可以解释一下吗?
为了获得预期的输出,我这样做:
hexdump -C test.txt
00000000 c3 b1 |..|
00000002
我认为我理解编码系统。
I am playing with the Unix hexdump utility. My input file is UTF-8 encoded, containing a single character ñ
, which is C3 B1
in hexadecimal UTF-8.
hexdump test.txt
0000000 b1c3
0000002
Huh? This shows B1 C3
- the inverse of what I expected! Can someone explain?
For getting the expected output I do:
hexdump -C test.txt
00000000 c3 b1 |..|
00000002
I was thinking I understood encoding systems.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是因为 hexdump 默认使用 16 位字,并且您正在小端架构上运行。因此,字节序列
b1 c3
被解释为十六进制字c3b1
。-C
选项强制 hexdump 使用字节而不是字。This is because hexdump defaults to using 16-bit words and you are running on a little-endian architecture. The byte sequence
b1 c3
is thus interpreted as the hex wordc3b1
. The-C
option forces hexdump to work with bytes instead of words.我找到了两种方法来避免这种情况:
或者
我认为 hexdump 决定文件通常是 16 位字小尾数法是愚蠢的。海事组织非常令人困惑。
I found two ways to avoid that:
or
I think it is stupid that hexdump decided that files are usually 16bit word little endian. Very confusing IMO.