int to bytes in python code example
Example 1: python convert string to bytes
data = "" #string
data = "".encode() #bytes
data = b"" #bytes
data = b"".decode() #string
data = str(b"") #string
Example 2: convert int to byte python
pythonCopy>>> (258).to_bytes(2, byteorder="little")
b'\x02\x01'
>>> (258).to_bytes(2, byteorder="big")
b'\x01\x02'
>>> (258).to_bytes(4, byteorder="little", signed=True)
b'\x02\x01\x00\x00'
>>> (-258).to_bytes(4, byteorder="little", signed=True)
b'\xfe\xfe\xff\xff'