Question

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?

Was it helpful?

Solution

To get precisely 8 bits, use string formatting:

A demo:

>>> '{0:08b}'.format(22)
'00010110'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top