0

How do I convert a decimal value to a binary value in python given a second variable that gives the number of bits to use?

I am trying to write a function that accepts two arguments: a positive or negative decimal number and the number of bits to use in the excess representation. So far, I can make the conversion between decimal and binary given an integer, but I'm not sure how to implement the number of bits for its notation.

Any ideas?

Alex Patel
  • 36
  • 1
  • 7
  • See the first answer on the duplicate: `'{0:08b}'.format(6)` (where 8 is the number of 0s and 6 is the decimal number to be converted) will work. – David Robinson May 01 '13 at 05:04
  • How are you proposing handling negative numbers with arbitrary bits? A sign bit? – dawg May 01 '13 at 05:22

0 Answers0