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'))