binascii.a2b_hex(hexstr)
binascii.unhexlify(hexstr)
Return the binary data represented by the hexadecimal string hexstr. This function is the inverse of b2a_hex(). hexstr must contain an even number of hexadecimal digits (which can be upper or lower case), otherwise a TypeError is raised.
1
2
3
4
5
6
7
|
>>> a
=
'\x00\x91\xe2\xbe\xf1\x00\x04\xc4\x94\xba\xf7\xa2\x11\xf7\x11f\xe4A\x1c\xcc'
>>>
import
binascii
>>> binascii.b2a_hex(a)
'0091e2bef10004c494baf7a211f71166e4411ccc'
>>> str1
=
"fadsfasf"
>>>
print
binascii.b2a_hex(str1)
'6661647366617366'
|
来源:http://www.dreamrunner.org/2011/11/convert-between-binary-and-ascii/