from hex to string python code example

Example 1: hex to string python

>>> bytes.fromhex('HexValue').decode('utf-8')
'string'
>>> bytes.fromhex('7368616b6564').decode('utf-8')
'shaked'

Example 2: python string to hex

hex_string = "0xAA"
# "0x" also required

an_integer = int(hex_string, 16)
# an_integer is a decimal value

hex_value = hex(an_integer)
print(hex_value)

Example 3: hex to string python

>>> b'\xde\xad\xbe\xef'.hex()
'deadbeef'

Example 4: hex to string python

>>> bytes.fromhex('deadbeef')
b'\xde\xad\xbe\xef'