Programming Examples
Python program to convert binary to decimal
Write a program to convert binary to decimal.
Solution
num=int(input("Enter Any Binary Number : "))
decimal=0
count=0
while num>0:
digit=num%10
decimal=decimal+digit*(2**count)
num=num//10
count=count+1
print("Decimal Value : ",decimal)
Output
Enter Any Binary Number : 101
Decimal Value : 5
======================
Enter Any Binary Number : 1001
Decimal Value : 9