字节字符串和数字互转

x = 53523566
# 数字转为字节字符串
nbytes, rem = divmod(x.bit_length(), 8)
if rem:
    nbytes += 1
print(nbytes)
print(x.to_bytes(nbytes, 'little'))

# 字节字符串转为数字
data = b'nxb40x03'
print(int.from_bytes(data, 'little'))
原文地址:https://www.cnblogs.com/c-x-a/p/14157625.html