Python int类型转换bytes
# int类型转bytes
# 指定4个字节的bytes
length = 4
args = 333
# 指定大端
res = args.to_bytes(length, byteorder='big')
print(res) # b'\x00\x00\x01M'
# 指定小端
res = args.to_bytes(length, byteorder='little')
print(res) # b'M\x01\x00\x00'
# int类型转bytes
# 指定4个字节的bytes
length = 4
args = 333
# 指定大端
res = args.to_bytes(length, byteorder='big')
print(res) # b'\x00\x00\x01M'
# 指定小端
res = args.to_bytes(length, byteorder='little')
print(res) # b'M\x01\x00\x00'