Integer to Binary string

Bengt Richter bokr at oz.net
Fri Dec 6 22:50:16 EST 2002


On Fri, 06 Dec 2002 15:23:08 -0800, Erik Max Francis <max at alcyone.com> wrote:

>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?
>
>It looks like most of the other respondants misunderstood your question
>(the mention of _itoa was the key).  Just use the str builtin:
>
>>>> i = 10
>>>> i
>10
>>>> str(i)
>'10'
>
I assumed he wanted to use radix 2. The protoype is

char *_itoa( int value, char *string, int radix );


Regards,
Bengt Richter



More information about the Python-list mailing list