Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python十六进制地址从字符串打包_Python_Hex_Pack - Fatal编程技术网

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))