Newbie: displaying binary numbers

Mike Fletcher mfletch at tpresence.com
Mon Jun 12 02:19:31 EDT 2000


Hmm, here's a naive implementation which will work for positive numbers:

>>> def bits( integer ):
... 	result = ''
... 	while integer:
... 		result = str(integer & 1) + result
... 		integer = integer >> 1
... 	return result
... 

See also:

http://www.deja.com/[ST_rn=ps]/getdoc.xp?AN=621175578&fmt=text

HTH,
Mike

-----Original Message-----
From: Steven Adams [mailto:adams_s at lab.eng.usyd.edu.au]
Sent: Monday, June 12, 2000 12:55 AM
To: python-list at python.org
Subject: Newbie: displaying binary numbers


Hi all,

I'm trying to display integers as binary numbers, I know there are the calls
for making hexadecimal and octal strings, but couldn't find anything for
binary?

are there any modules, or operations not in the docs?

all I need is to convert a number to a binary with n bits.

thanks, Steven


-- 
http://www.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list