def polmul(n1,n2):
n1 = int (n1, 2)
s = int ('0', 2)
for c in n2 [:: -1]:
if (c == '1'):
s = s ^ n1
n1*=2
Bin_out = bin(s)[2:].zfill(2)
Mul = str(Bin_out)
return Mul
n1 = '0000011'
n2 = '100010111'
x = polmul(n1,n2)
(结果为1100111001)
它在开头跳过零。
我需要结果000001100111001
请帮忙
Tags:
这样就可以了,因为
*.zfill(fill_width)
在左边用零填充字符串到fill_width
(fill_width=15
)相关问题 更多 >
编程相关推荐