# Convert binary numbers to decimal numbers
# by Sara Sprenkle, 10.03.2007

print 
print "This program converts binary numbers to decimal numbers."
print

def isBinary(str):
    if not str.isdigit():
        return False
    
    for ch in str:
        if ch != "0" and ch != "1":
            return False
    return True

binary_string = raw_input("Enter a number in binary: ")

while not isBinary(binary_string):
    print "Sorry, that is not a binary string"
    binary_string = raw_input("Enter a number in binary: ")

# only get to here if the string is binary

exponent = len(binary_string)-1
    
dec_value = 0

for bit in binary_string:
    bit = int(bit)
    print bit,"* 2^%d" % exponent
    dec_value += bit * (2 ** exponent)
    
    exponent -= 1
    
    
print "The decimal value is", dec_value