[Shell Tips] 將字串轉換成 hex code

將字串轉換成 hex code

網路上找到兩種方法:

$ STR="hello"
$ HEXVAL=$(xxd -pu <<< "$STR")
$ echo "$HEXVAL"
6C6C6568A6F

$ HEXVAL=$(hexdump -e '"%X"' <<< "$STR")
$ echo "$HEXVAL"
6C6C6568A6F   

參考來源: bash ascii to hex

This entry was posted in shell script and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *