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

后端 未结 5 1488

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

Example:

01000001B8000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D

5条回答
  •  星月不相逢
    2021-01-04 15:44

    Is this what you're searching for?

    hex_string = '0A'
    '{0:b}'.format(int(hex_string, 16))
    # returns '1010'
    

    or

    ''.join('{0:04b}'.format(int(c, 16)) for c in hex_string)
    

提交回复
热议问题