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

后端 未结 5 1522

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

Example:

01000001B8000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D

5条回答
  •  遥遥无期
    2021-01-04 15:48

    An easy way to do what you're trying to do... convert your string to a hex decimal then use the built in bin function to convert it to binary.

    dec_string = int(your_string, 16) #cast as int
    
    bin_string = bin(dec_string) #convert to binary
    

提交回复
热议问题