Frage

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?

War es hilfreich?

Lösung

To get precisely 8 bits, use string formatting:

A demo:

>>> '{0:08b}'.format(22)
'00010110'
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top