469,306 Members | 1,901 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

converting to a binary number?

I'm having some trouble finding a function that converts numbers
(whether integer, hex, whatever) to its binary representation. Is there one?

Thanks.
Mar 24 '06 #1
4 3441

John Salerno wrote:
I'm having some trouble finding a function that converts numbers
(whether integer, hex, whatever) to its binary representation. Is there one?

Thanks.


Get the Gnu Multiple Precision library for Python module (Google GMPY).
import gmpy
help(gmpy.digits) Help on built-in function digits:
digits(...)
digits(x[,base]): returns Python string representing x in the
given base (2 to 36, default 10 if omitted or 0); leading '-'
present if x<0, but no leading '+' if x>=0. x must be an mpz,
or else gets coerced into one.
for i in range(16):

print gmpy.digits(i,2)

0
1
10
11
100
101
110
111
1000
1001
1010
1011
1100
1101
1110
1111

Mar 24 '06 #2
that's great! I will try! :-))

Mar 24 '06 #3
John Salerno wrote:
I'm having some trouble finding a function that converts numbers
(whether integer, hex, whatever) to its binary representation. Is there one?


You might like this recipe:
http://aspn.activestate.com/ASPN/Coo.../Recipe/111286

Kent
Mar 24 '06 #4
me********@aol.com wrote:
John Salerno wrote:
I'm having some trouble finding a function that converts numbers
(whether integer, hex, whatever) to its binary representation. Is there one?

Thanks.


Get the Gnu Multiple Precision library for Python module (Google GMPY).


Thanks!
Mar 24 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Sverre Bakke | last post: by
reply views Thread by Dan Stromberg | last post: by
2 posts views Thread by Mariusz Sakowski | last post: by
8 posts views Thread by Rick | last post: by
18 posts views Thread by No Such Luck | last post: by
5 posts views Thread by ria3 | last post: by
1 post views Thread by girl23 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.