Subject: Re: Binary numbers

venkata subramanian venkatasubramanian at gmail.com
Wed Jun 8 12:47:04 EDT 2005


> Em Quarta 08 Junho 2005 09:38, Guyon Morée escreveu:
> > Don't know if this is what you mean, but:
> >
> > Binary to decimal:
> > >>> bin_num = '100001011'
> > >>> int(bin_num, 2)
> >
> > 267
> 
> Dont know this way of using it. Thanks for the teachings :)
> 
> See ya !




 >>> def binary(i):
...     ls=[]
...     while 1:
...             ls.append(i&1)
...             i>>=1
...             if i==0:
...                     break
...     return "".join(str(x) for x in reversed(ls))
...
>>> binary(20)
'10100'



More information about the Python-list mailing list