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 2021 CCC Practice Test Hindi Python Programming Tutorials 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 Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz