给定十六进制和形成字节
查找要字符串的字节
def hex_to_b:
return bytes.fromhex('abc')
#now you have a byte type string
#looking to decode back to the string
#failure of transformation
hex_to_b().decode(encoding="utf-8",errors="strict")
要将字节转换为十六进制,反之亦然,请使用内置的binascii
模块。
https://docs.python.org/3/library/binascii.html
例:
>>> from binascii import hexlify, unhexlify
>>> unhexlify('deadbeef')
b'xdexadxbexef'
>>> hexlify(b'xdexadxbexef').decode()
'deadbeef'
确保传递了有效的十六进制字符串。