Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Input
- bin = int(input("Type a binary number"))
- # Process
- str_bin = str(bin)
- power = 0
- lengh = len(str_bin)
- total = 0
- while lengh > 0:
- unit = str_bin[lengh-1: lengh]
- int_unit = int(unit)
- total += int_unit * 2 ** power
- power += 1
- lengh -= 1
- print("The decimal value for this binary number is", total)
Advertisement
Add Comment
Please, Sign In to add comment