Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def convert_2_to_10(n):
- dec = 0
- multiplier = 0
- for b in n[::-1]:
- dec += int(b)*2**multiplier
- multiplier +=1
- return dec
- #print str(b) + " " + str(dec) + " ||",
- print convert_2_to_10("10") # 2
- print convert_2_to_10("1000") # 8
- print convert_2_to_10("1010") # 10
- print convert_2_to_10("11111") # 31
- print convert_2_to_10("101010") # 42
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement