Advertisement
maynul67

Binary to decimal converter

Jul 12th, 2021
587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.27 KB | None | 0 0
  1. def bin_dec(binary):
  2.     decimal = 0
  3.     i = 0
  4.     while (binary != 0):
  5.         rem = binary % 10
  6.         last_digit = rem * pow(2,i)
  7.         decimal = decimal + last_digit
  8.         binary = binary // 10
  9.         i += 1
  10.     return decimal
  11.  
  12. num = int(input("Enter binary number"))
  13. result = bin_dec(num)
  14. print(result)
  15.  
  16.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement