发布网友 发布时间:2022-05-01 00:32
共1个回答
热心网友 时间:2022-06-21 10:10
import structPython 2.7.12 (default, Nov 22 2016, 17:23:24)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "copyright", "credits" or "license()" for more information.
>>> import struct
>>> struct.pack("f", 3.14).encode('hex')
'c3f54840'
>>> round(struct.unpack('f','c3f54840'.decode('hex'))[0],5)
3.14
>>> struct.pack("i", 200).encode('hex')
'c8000000'
>>> struct.unpack('i','c8000000'.decode('hex'))[0]
200
>>> '68656c6c6f'.decode('hex')
'hello'
>>> 'hello'.encode('hex')
'68656c6c6f'
>>> import re
>>> '{%s}' % ','.join([str(int(i,16)) for i in re.findall(r'.{2}','68656c6c6f')])
'{104,101,108,108,111}'
>>> ''.join([hex(int(i))[2:] for i in re.findall(r'\d+','{104,101,108,108,111}')])
'68656c6c6f'