Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 Python 中的十六进制转换有一些问题。
我有一个代表十六进制数字的字符串 -"02"我想将其转换为另一个十六进制数字并将其0x02连接到另一个十六进制数字。
"02"
0x02
我的代码:
valToWrite1 = '\x3c' valToWrite2 = '02'
我想加入这两个值,这样我的结果就是"\x3c\x02". 保持前导零很重要。
"\x3c\x02"
你需要binascii.unhexlify():
binascii.unhexlify()
>>> import binascii >>> binascii.unhexlify("02") '\x02' >>> '\x3c' + _ '<\x02'