80. Python Program to Convert Binary value into Decimal number.
How does this program work?
- This program is used to convert Binary value into equivalent of Decimal number using Python.
- That means convert number with base value 2 to base value 10.
- The integer entered by user will store in one variable. Divide that number by 10.
- Store the remainder and that will be multiplied by base value, Declare base value and initialize with 1 means (2^0).
Here is the code
def binaryToDecimal(b):
a = b
d = 0
i = 0
n = 0
while(b != 0):
dec = b % 10
d = d + dec * pow(2, i)
b = b//10
i += 1
print(d)
b = int(input( "Enter a binary number: "))
print("The equivalent Decimal number is : ",end='')
binaryToDecimal(b)