十六进制转储混乱 [英] hexdump confusion
问题描述
我正在使用unix hexdump实用程序.我的输入文件是UTF-8编码的,包含单个字符ñ
,在十六进制UTF-8中为C3 B1
.
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
嗯?这显示了B1 C3
-与我期望的相反!有人可以解释吗?
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 understand encoding systems..
推荐答案
这是因为hexdump默认使用16位字,并且您使用的是Little-endian体系结构.因此,字节序列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.
这篇关于十六进制转储混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!