在我的情况下如何正确地乘法

2024-04-20 07:06:52 发布

您现在位置:Python中文网/ 问答频道 /正文

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: inforreturnifbindefoutint