How to convert hex to byte in Python

2 Answers

0 votes
import binascii

s = 'Ύμνος - abc'

byte = s.encode('utf-8')
print(byte)
hex = binascii.hexlify(byte).decode('utf-8')
print(hex)

byte = bytes.fromhex(hex)
print(byte)




'''
run:

b'\xce\x8e\xce\xbc\xce\xbd\xce\xbf\xcf\x82 - abc'
ce8ecebccebdcebfcf82202d20616263
b'\xce\x8e\xce\xbc\xce\xbd\xce\xbf\xcf\x82 - abc'

'''

 



answered Apr 30, 2021 by avibootz
0 votes
import binascii
from binascii import unhexlify

s = 'Ύμνος - abc'

byte = s.encode('utf-8')
print(byte)
hex = binascii.hexlify(byte).decode('utf-8')
print(hex)

byte = unhexlify(hex)
print(byte)




'''
run:

b'\xce\x8e\xce\xbc\xce\xbd\xce\xbf\xcf\x82 - abc'
ce8ecebccebdcebfcf82202d20616263
b'\xce\x8e\xce\xbc\xce\xbd\xce\xbf\xcf\x82 - abc'

'''

 



answered Apr 30, 2021 by avibootz

Related questions

1 answer 110 views
3 answers 279 views
279 views asked Apr 30, 2021 by avibootz
1 answer 105 views
1 answer 107 views
...