0

Im working on a program which converts binary into integers (easy enough) however I then need to convert the integers back into 8bit binary representation. I have had a look, and I can do it mathematically, but I was wondering if there was a handy python function that did this?

Chris Headleand
  • 6,003
  • 16
  • 51
  • 69
  • possible duplicate of [Converting integer to binary in python](http://stackoverflow.com/questions/10411085/converting-integer-to-binary-in-python) – FrobberOfBits Apr 15 '14 at 17:58

1 Answers1

2

To get precisely 8 bits, use string formatting:

A demo:

>>> '{0:08b}'.format(22)
'00010110'
anon582847382
  • 19,907
  • 5
  • 54
  • 57