How to convert byte to hex in Python

3 Answers

0 votes
s = 'Ύμνος - abc'

byte = s.encode('utf-8')

hex = byte.hex()

print(hex)





'''
run:

ce8ecebccebdcebfcf82202d20616263

'''

 



answered Apr 30, 2021 by avibootz
0 votes
import binascii

s = 'Ύμνος - abc'

byte = s.encode('utf-8')

hex = binascii.hexlify(byte)

print(hex)





'''
run:

b'ce8ecebccebdcebfcf82202d20616263'

'''

 



answered Apr 30, 2021 by avibootz
0 votes
import binascii

s = 'Ύμνος - abc'

byte = s.encode('utf-8')

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

print(hex)





'''
run:

ce8ecebccebdcebfcf82202d20616263

'''

 



answered Apr 30, 2021 by avibootz

Related questions

1 answer 110 views
2 answers 170 views
170 views asked Apr 30, 2021 by avibootz
1 answer 105 views
1 answer 107 views
...