468,736 Members | 2,128 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,736 developers. It's quick & easy.

Re: howto print binary number

On May 7, 3:31*pm, Mensanator <mensana...@aol.comwrote:
On May 7, 3:13*pm, dmitrey <dmitrey.kros...@scipy.orgwrote:
hi all,
could you inform how to print binary number?
I.e. something like
print '%b' % my_number
it would be nice would it print exactly 8 binary digits (0-1, with
possible start from 0)
Thank you in advance, D

The gmpy works good.
>import gmpy
print gmpy.digits(66,2).zfill(8)

01000010
>>print '\n'.join( [ ''.join( [ str( a>i & 1 ) for i in range( 7, -1, -1) ]
) for a in range( 10 ) ] )
00000000
00000001
00000010
00000011
00000100
00000101
00000110
00000111
00001000
00001001
Jun 27 '08 #1
0 1043

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Rusty Shackleford | last post: by
12 posts views Thread by neutrino | last post: by
11 posts views Thread by CSN | last post: by
3 posts views Thread by durumdara | last post: by
14 posts views Thread by mosi | last post: by
5 posts views Thread by dmitrey | last post: by
45 posts views Thread by hank | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.