Easy methods to Convert Hex to Byte in Python


If it is advisable to convert Hex to Byte in Python, then you are able to do one of many following:

Choice 1 – Utilizing binascii

import binascii
str_val = 'This can be a take a look at'.encode('utf-8')
hex_val = binascii.hexlify(str_val).decode('utf-8')

print(hex_val)

Choice 2 – Utilizing bytes.fromhex()

hex_val = 'This can be a take a look at'

print(bytes.fromhex(hex_val))

Choice 3 – Utilizing unhexlify

import binascii
from binascii import unhexlify

str_val = 'This can be a take a look at'.encode('utf-8')
hex_val = binascii.hexlify(str_val).decode('utf-8')

print('String worth: ', str_val.decode('utf-8'))
print('Hexadecimal: ', hex_val)
print('Byte worth: ', unhexlify(hex_val))
See also  Web page not discovered : Software program Engineering Radio

Leave a Reply