0
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)

(result is 1100111001)

It is skipping zeros at the beginning. I need result 000001100111001 Please help

luoluo
  • 5,353
  • 3
  • 30
  • 41

1 Answers1

0
Bin_out = bin(s)[2:].zfill(15)

will do the trick, since *.zfill(fill_width) pads string on the left with zeros to fill_width (fill_width=15 in your case)

gizzmole
  • 1,437
  • 18
  • 26
  • 2
    While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – rollstuhlfahrer Feb 26 '18 at 09:52