我试图表达一个将二进制数表示为实二进制数的列表,如 (1,3,6) 表示0b100101
。首先,我尝试将它们相加为 2^1+2^3+2^6 然后转换为二进制
with open('DATA.txt') as f:
for line in f:
myLine=line.rstrip().split("\t")
print [bin(2**int(l)) for l in myLine[1:5]]
我将它转换为a
如下所示的列表
>>> a=['0b10000000000000000000000000', '0b100000000000', '0b100000000000000000000000000000']
>>> a[1]|a[2]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for |: 'str' and 'str'
>>> bin(a[1])+bin(a[2])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object cannot be interpreted as an index
所以
我应该如何将幂向量转换为二进制数,即如何从幂二进制数表示转换为实数二进制数表示?
简单的例子
输入
['0b10000000000000000000000000', '0b100000000000', '0b100000000000000000000000000000']
预期输出
0b100010000000000000100000000000