Python:binascii库 - 二进制和 ASCII 码互转
import binascii
"""
binascii 模块包含很多在二进制和二进制表示的各种ASCII码之间转换的方法
"""
s = b'hello'
# 返回二进制数据的十六进制表示形式
h = binascii.hexlify(s)
print(binascii.hexlify(s))
# OR
print(binascii.b2a_hex(s))

# 返回由十六进制字符串表示的二进制数据
print(binascii.a2b_hex(h))
# OR
print(binascii.unhexlify(h))
Subscribe to weigr
Receive the latest updates directly to your inbox.
Verification
This entry has been permanently stored onchain and signed by its creator.