[Tutor] Binary to Decimal conversion

Moos Heintzen iwasroot at gmail.com
Tue Mar 10 03:53:14 CET 2009


You're making it more complicated than it needs to.
Also, you first used binnum then binum, and you didn't define binsum.

It could easily be done like this:

binnum = raw_input("Please enter a binary number:  ")
decnum = 0
rank = 1

for i in reversed(binnum):
    decnum += rank * int(i)
    rank *= 2

Moos


More information about the Tutor mailing list