pythonCopy>>> (258).to_bytes(2, byteorder="little")
b'x02x01'
>>> (258).to_bytes(2, byteorder="big")
b'x01x02'
>>> (258).to_bytes(4, byteorder="little", signed=True)
b'x02x01x00x00'
>>> (-258).to_bytes(4, byteorder="little", signed=True)
b'xfexfexffxff'
bytes = (-32757).to_bytes(2, 'little', signed = True) #store value in 2 bytes
#bytes 2 int
print(int.from_bytes([bytes[0], bytes[1]], 'little', signed=True)) #returns -32767
>>> bytes([2])
b'x02`
>>> bytes(10)
b'x00x00x00x00x00x00x00x00x00x00'