binary to decimal conversion

Michael Esveldt dante at oz.net
Sat Mar 18 16:04:07 EST 2000


This morning I wrote a function that takes a binary number as a string 
and converts it to an integer. There must be a way to optimize this 
function, anyone have some tips?

def btoi(num):
    output = 0
    col = range(len(num))
    col.reverse()
    for bit in range(len(num)):
        output = output + pow(2,col[bit])*int(num[bit])
    return output

Thanks,
Michael
_______________________________________________________________
dante at oz.net - Michael Esveldt - #FightThePower on Openprojects



More information about the Python-list mailing list