0

I am converting two integers to binary. Based on the maximum length of the two conversions, I want to fill 0s for the short conversion so that the two conversions will have the same length. I am thinking I can pass the m = max(length) as a variable to reformat a '{0:mb}'.format(x). But this does not work.

Is there a way I can do this or another way to work this? Please help.

ggorlen
  • 44,755
  • 7
  • 76
  • 106
DoriTheFish
  • 23
  • 1
  • 1
  • 4
  • Possible duplicate of [Convert to binary and keep leading zeros in Python](https://stackoverflow.com/questions/16926130/convert-to-binary-and-keep-leading-zeros-in-python) – ggorlen Jan 15 '19 at 22:59
  • `format(your_number, '#0%db' % your_desired_length)` – ggorlen Jan 15 '19 at 23:04

0 Answers0