美文网首页python
python下的byte数值转换

python下的byte数值转换

作者: 小白兔胡萝卜 | 来源:发表于2021-11-19 15:04 被阅读0次

import struct

# unsigned char

def byte2float(x):

    return struct.unpack('<f', struct.pack('4B', *x))[0]

# unsigned int

def byte2Uint(x):

    return struct.unpack('<I', struct.pack('4B', *x))[0]

def float2byte(f):

    return [hex(i)for i in struct.pack('f', f)]

data_byte1 = int(1324).to_bytes(length=4, byteorder='big', signed=True)

print(data_byte1) 

data_byte2 = int().from_bytes(data_byte1, byteorder='big', signed=True)

print(data_byte2)

相关文章

网友评论

    本文标题:python下的byte数值转换

    本文链接:https://www.haomeiwen.com/subject/eogqoltx.html