how to encode integer as bytes in python code example
Example 1: bytes to string python
# utf-8 is used here because it is a very common encoding, but you
# need to use the encoding your data is actually in.
bytes = b'abcde'
bytes.decode("utf-8")
'abcde'
Example 2: python hex to bytes string
hexadecimal_string = "AB"
byte_array = bytearray.fromhex(hexadecimal_string)
print(byte_array)