Advertisement
Guest User

3.4.2

a guest
Oct 10th, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. def convert_2_to_10(n):
  2.     dec = 0
  3.     multiplier = 0
  4.     for b in n[::-1]:
  5.         dec += int(b)*2**multiplier
  6.         multiplier +=1
  7.     return dec    
  8.         #print str(b) + " " + str(dec) + " ||",
  9.  
  10. print convert_2_to_10("10")       # 2
  11. print convert_2_to_10("1000")     # 8
  12. print convert_2_to_10("1010")     # 10
  13. print convert_2_to_10("11111")    # 31
  14. print convert_2_to_10("101010")   # 42
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement