Python十六进制地址从字符串打包
这是正确的:Python十六进制地址从字符串打包,python,hex,pack,Python,Hex,Pack,这是正确的: packed = struct.pack('<L',0x7c023a4f) packed=struct.pack(“您可以使用literal\u eval在打包前将字符串作为十六进制数进行求值: from ast import literal_eval address = '0x7c023a4f' packed = struct.pack('<L', literal_eval(address)) packed # 'O:\x02|' 从ast导入文字\u评估 地址
packed = struct.pack('<L',0x7c023a4f)
packed=struct.pack(“您可以使用literal\u eval
在打包前将字符串作为十六进制数进行求值:
from ast import literal_eval
address = '0x7c023a4f'
packed = struct.pack('<L', literal_eval(address))
packed
# 'O:\x02|'
从ast导入文字\u评估
地址='0x7c023a4f'
packed=struct.pack(“将其转换为整数:
address = '0x7c023a4f'
packed = struct.pack('<L', int(address, 16))
地址='0x7c023a4f'
packed=struct.pack('谢谢,这正是我想要的。
address = '0x7c023a4f'
packed = struct.pack('<L', int(address, 16))