binary to decimal conversion

Michael Esveldt dante at
Sat Mar 18 22:04:07 CET 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))
    for bit in range(len(num)):
        output = output + pow(2,col[bit])*int(num[bit])
    return output

dante at - Michael Esveldt - #FightThePower on Openprojects

More information about the Python-list mailing list