Converting a Binary
Mike Fletcher
mfletch at tpresence.com
Tue May 9 12:39:16 EDT 2000
See module struct in the documentation.
struct.pack( 'i', yourinteger )
Enjoy,
Mike
-----Original Message-----
From: Jeff Massung [mailto:jmassung at magpiesystems.com]
Sent: Tuesday, May 09, 2000 12:19 PM
To: python-list at python.org
Subject: Re: Converting a Binary
AMR wrote in message <8f98bk$a6c28 at esiami.tsai.es>...
>What module I need to convert a number to binary?,
In string format? Assuming 24-bit integer:
def itob(i):
t=2**23
b=''
while i>0:
if i>=t:
b=b+'1'
i=i-t
elif b!='':
b=b+'0'
t=t/2
return b
Sorry, I'm new to Python, so if some of this can be done easier or quicker,
I'd like to know how, too ;)
Jeff
--
http://www.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list