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

CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad