bash的ASCII到十六进制 [英] bash ascii to hex
本文介绍了bash的ASCII到十六进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
想知道是否有人能帮助我在bash ASCII码转换为十六进制。
例如:code:
#!/斌/庆典
STR =你好
#Convert十六进制
HEXVAL = $#STR(十六进制吗?)
我想hexval有值:
68656C6C6F(你好十六进制)
解决方案
$ STR =你好
$ HEXVAL = $(XXD -pu<<<$ STR)
$回声$ HEXVAL
6C6C6568A6F
或者
$ HEXVAL = $(hexdump都-e'%X'<<<$ STR)
$回声$ HEXVAL
6C6C6568A6F
小心使用'%X
;它既有单引号和双引号。
was wondering if anyone could help me with converting ascii to hex in bash. Example code:
#!/bin/bash
STR = "hello"
#Convert to hex
HEXVAL = $STR #(in hex here?)
I want hexval to have the value: 68656C6C6F (hello in hex)
解决方案
$ STR="hello"
$ HEXVAL=$(xxd -pu <<< "$STR")
$ echo "$HEXVAL"
6C6C6568A6F
Or:
$ HEXVAL=$(hexdump -e '"%X"' <<< "$STR")
$ echo "$HEXVAL"
6C6C6568A6F
Careful with the '"%X"'
; it has both single quotes and double quotes.
这篇关于bash的ASCII到十六进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文