## Binary - denary converter problems...

A forum for general discussion of the Python programming language.

### Binary - denary converter problems...

Hi, please help me with my decimal to denary converter. The problem is with the sum total counter 'denarynum', it only seems to add the last number.

Code: Select all
`string=str(int(input("Enter a binary number <10000 ")))stringlength=len(string)length=int(stringlength)denarynum=int(0)if length == 1:    num1=int(string[0])    if num1 == 1:        denarynum=denarynum+1if length == 2:    num2=int(string[1])    if num2 == 1:        denarynum=denarynum+2if length == 3:    num3=int(string[2])    if num3 == 1:        denarynum=denarynum+4if length == 4:    num4=int(string[3])    if num4 == 1:        denarynum=denarynum+8if length == 5:    num5=int(string[4])    if num5 == 1:        denarynum=denarynum+16if length == 6:    num6=int(string[5])    if num6 == 1:        denarynum=denarynum+32if length == 7:    num7=int(string[6])    if num7 == 1:        denarynum=denarynum+64print("The binary number",string,"in decimal is",denarynum,"in decimal")`

Thanks for any help, it is much appreciated!
Last edited by micseydel on Wed Sep 25, 2013 7:07 pm, edited 1 time in total.
Reason: Code tags, first post lock.
pimaster

Posts: 3
Joined: Tue Sep 24, 2013 4:17 pm