How to convert hex to bytes in Python

2 Answers

0 votes
b = bytes.fromhex('abcdef')

print(b)



'''
run:

b'\xab\xcd\xef'

'''

 



answered Apr 9, 2021 by avibootz
0 votes
import binascii

b = 'питон - python'.encode('utf-8')
hex = binascii.hexlify(b).decode('utf-8')
print(hex)

print(bytes.fromhex(hex))
 
 
 
'''
run:
 
d0bfd0b8d182d0bed0bd202d20707974686f6e
b'\xd0\xbf\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd - python'
 
'''

 



answered Apr 9, 2021 by avibootz

Related questions

1 answer 217 views
3 answers 348 views
348 views asked Apr 9, 2021 by avibootz
1 answer 257 views
1 answer 227 views
1 answer 253 views
253 views asked Apr 25, 2021 by avibootz
3 answers 437 views
437 views asked Apr 9, 2021 by avibootz
...