ASCII /十六进制转换在bash [英] Ascii/Hex convert in bash
问题描述
我现在做这种方式:
[root@~]# echo Aa|hexdump -v
0000000 6141 000a
0000003
[root@~]# echo -e "\x41\x41\x41\x41"
AAAA
但它不完全表现,因为我想,
But it's not exactly behaving as I wanted,
机管局的十六进制形式
应 4161
,但输出 6141 000A
,这似乎不是决策意识。
the hex form of Aa
should be 4161
,but the output is 6141 000a
,which seems not making sense.
和ASCII码进行十六进制的时候,有另一种工具,这样我不需要preFIX \\ X
?
and when performing hex to ascii,is there another utility so that I don't need the prefix \x
?
推荐答案
究其原因是因为 hexdump都
默认情况下,打印出16位整数,而不是字节。如果你的系统有他们,高清
(或 hexdump都-C
)或 XXD
将提供那么令人惊讶的输出 - 如果不是, OD -t X1
是一个POSIX标准的方式来获得逐字节的十六进制输出。您可以使用 OD -t X1C
同时显示字节十六进制值和相应的字母。
The reason is because hexdump
by default prints out 16-bit integers, not bytes. If your system has them, hd
(or hexdump -C
) or xxd
will provide less surprising outputs - if not, od -t x1
is a POSIX-standard way to get byte-by-byte hex output. You can use od -t x1c
to show both the byte hex values and the corresponding letters.
如果您有 XXD
(其中附带VIM),你可以使用 XXD -r
从转换回十六进制(从相同的格式 XXD
生产)。如果你只是有简单的十六进制(就在4161,这是由 XXD -p
制作),可以使用 XXD -r -p
转换回来。
If you have xxd
(which ships with vim), you can use xxd -r
to convert back from hex (from the same format xxd
produces). If you just have plain hex (just the '4161', which is produced by xxd -p
) you can use xxd -r -p
to convert back.
这篇关于ASCII /十六进制转换在bash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!