我有一个十六进制数列表作为字符串,我想将它们全部转换为二进制。我正在使用Python 3.有什么好办法呢?
编辑:这些数字的格式为'0x23051fb2'
,即它们以0x
开头。
答案 0 :(得分:3)
hexlist = ['0x23051fb2', '0xAB', '0xAC']
binlist = [bin(int(x, 16)) for x in hexlist]
现在,如果我们print(binlist)
,我们得到:
['0b100011000001010001111110110010', '0b10101011', '0b10101100']
答案 1 :(得分:0)
lst = ['0x1A', '0xFF', 'FF']
print map(lambda x: bin(int(x, 16)), lst)
输出:
['0b11010', '0b11111111', '0b11111111']