decimal to binary

Manish Jethani manish.j at gmx.net
Fri Jul 25 08:58:48 EDT 2003


manuel wrote:

> How to convert a decimal to binary ?

def foo(i):
    b = ''
    while i > 0:
        j = i & 1
        b = str(j) + b
        i >>= 1
    return b

Maybe this is inefficient, but...

-Manish

-- 
Manish Jethani (manish.j at gmx.net)
phone (work) +91-80-51073488





More information about the Python-list mailing list