Converting a Binary

Jeff Massung jmassung at magpiesystems.com
Tue May 9 12:19:18 EDT 2000


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





More information about the Python-list mailing list