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?

1

1 Answer 1

2

To get precisely 8 bits, use string formatting:

A demo:

>>> '{0:08b}'.format(22)
'00010110'
Sign up to request clarification or add additional context in comments.

3 Comments

Hi, this puts 0b at the beginning of the string, and it isn't in 8bit. is there a way to fix that?
Perfect, thanks... will accept in 7 mins when the software lets me! lol
@ChrisHeadleand Good, glad to have been of assistance. Upvotes are also greatly appreciated if you haven't already. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.