【发布时间】:2018-12-20 11:11:47
【问题描述】:
我有一个 info_address,我想将其转换为带分隔符的十六进制
info_address_original = b'002dd748'
我想要的是
info_address_coded = b'\x00\x2d\xd7\x48'
info_address_original = b'002dd748'
info_address_intermediary = info_address_original.decode("utf-8") # '002dd748'
info_address_coded = bytes.fromhex( info_address_intermediary ) # b'\x00-\xd7H'
我得到了
info_address_coded = b'\x00-\xd7H'
如何正确地将这样的字节字符串转换为分隔的十六进制?它在 Python 2 中隐含地工作,但在 Python 3 中却没有按照我想要的方式工作。
【问题讨论】: