In python, how to convert a hex ascii string to raw internal binary string?

后端 未结 5 1529

In python, how to convert a hex ASCII string to binary string?

Example:

01000001B8000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D

5条回答
  •  情深已故
    2021-01-04 15:54

    You probably need the .decode('hex') method of strings (Python 2.x).

    data= ("01000001B8000102030405060708090A0B0C0D0E0F10111213141516"
        "1718191A1B1C1D1E1F202122232425262728292A2B"
        "2C2D2E2F303132333435362021222324")
    data.decode('hex')
    

    Otherwise, you can use base64.b16decode, but you might want to supply a True to the second parameter (casefold) if your input contains lowercase hex digits A to F.

提交回复
热议问题