我是python初学者,抱歉…我有一系列这样的数据
b'Bx86xfexcax00x00x00x00x04x08x00x00xffxffxffxff'
转换成十六进制
['0x42', '0x86', '0xfe', '0xca', '0x0', '0x0', '0x0', '0x0', '0x4', '0x8', '0x0', '0x0', '0xff', '0xff', '0xff', '0xff']
但是我想把它变成这样的
0x4286feca, 0x00004800, 0xffffffff
我该怎么做?非常感谢
下面的代码>
brA = [b for b in struct.unpack(str(len(data))+'B',temp)]
sent_val = [str(hex(v)) for v in brA]
data = b'Bx86xfexcax00x00x00x00x04x08x00x00xffxffxffxff'
dwords_as_str = ["0x" + data[i:i+4].hex() for i in range(0, len(data), 4)]
print(dwords_as_str)
输出:
['0x4286feca', '0x00000000', '0x04080000', '0xffffffff']
:
- https://docs.python.org/3/library/functions.html func-range
- https://docs.python.org/3/library/stdtypes.html bytes.hex
- https://docs.python.org/3/tutorial/datastructures.html列表理解