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

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad