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)
▶ RUN

Output/ Explanation:

Enter Any Binary Number : 101

Decimal Value :  5

======================

Enter Any Binary Number : 1001

Decimal Value :  9

Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad