Integer to Binary string

Alfred Morgan amorgan at netlojix.com
Fri Dec 6 14:24:26 EST 2002


def bin(i):
     s = ''
     while i:
         s = (i & 1 and '1' or '0') + s
         i >>= 1
     return s or '0'


srijit at yahoo.com wrote:
> I would like to know the most efficient Pythonic way to convert an
> integer to a binary string. Any suggestions?
> Is there any Python function similar to _itoa?
> 
> Thanks




More information about the Python-list mailing list