hex string to character in python

后端 未结 4 1176
心在旅途
心在旅途 2021-01-01 20:37

I have a hex string like:

data = \"437c2123\"

I want to convert this string to a sequence of characters according to the ASCII table. The

4条回答
  •  鱼传尺愫
    2021-01-01 21:04

    In Python2

    >>> "437c2123".decode('hex')
    'C|!#'
    

    In Python3 (also works in Python2, for <2.6 you can't have the b prefixing the string)

    >>> import binascii
    >>> binascii.unhexlify(b"437c2123")
    b'C|!#'
    

提交回复
热议问题