hexadecimal string to byte array in python

前端 未结 8 1835
孤城傲影
孤城傲影 2020-11-22 11:53

I have a long Hex string that represents a series of values of different types. I wish to convert this Hex String into a byte array so that I can shift each value out and co

8条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 12:30

    def hex2bin(s):
        hex_table = ['0000', '0001', '0010', '0011',
                     '0100', '0101', '0110', '0111',
                     '1000', '1001', '1010', '1011',
                     '1100', '1101', '1110', '1111']
        bits = ''
        for i in range(len(s)):
            bits += hex_table[int(s[i], base=16)]
        return bits
    

提交回复
热议问题