By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,100 Members | 2,979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,100 IT Pros & Developers. It's quick & easy.

Number to binary string

P: 4
Hi everyone,

i would like to know if there is in python a way of converting a number into its 8bit long binary representation? in fact i know that the function bin() does that but for small numbers not in 8bit representation.
bin(56) returns 0b111000 (which is a 6bit representation)
i would like to have this:
bin(56) -> 0b00111000 (8bit representation)
or bin(2) -> 0b00000010
is that possible in python or do i have to write my own function for this?

May 24 '11 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.