十六进制转储输出顺序

发布于 2024-09-01 23:42:55 字数 383 浏览 8 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

层林尽染 2024-09-08 23:42:55

这是因为 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 word c3b1. The -C option forces hexdump to work with bytes instead of words.

心安伴我暖 2024-09-08 23:42:55

我找到了两种方法来避免这种情况:

hexdump -C file

或者

od -tx1 < file

我认为 hexdump 决定文件通常是 16 位字小尾数法是愚蠢的。海事组织非常令人困惑。

I found two ways to avoid that:

hexdump -C file

or

od -tx1 < file

I think it is stupid that hexdump decided that files are usually 16bit word little endian. Very confusing IMO.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文