字节字符串和数字互转
x = 53523566
# 数字转为字节字符串
nbytes, rem = divmod(x.bit_length(), 8)
if rem:
nbytes += 1
print(nbytes)
print(x.to_bytes(nbytes, 'little'))
# 字节字符串转为数字
data = b'n\xb40\x03'
print(int.from_bytes(data, 'little'))
x = 53523566
# 数字转为字节字符串
nbytes, rem = divmod(x.bit_length(), 8)
if rem:
nbytes += 1
print(nbytes)
print(x.to_bytes(nbytes, 'little'))
# 字节字符串转为数字
data = b'n\xb40\x03'
print(int.from_bytes(data, 'little'))