Pregunta

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?

¿Fue útil?

Solución

To get precisely 8 bits, use string formatting:

A demo:

>>> '{0:08b}'.format(22)
'00010110'
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top