• Register

If you don’t know how to convert binary to decimal in python then don’t worry. In this tutorial, we will convert binary to decimal using python.

What is Binary?

First, we need to know what is binary and how it works in coding and computers. So binary is a numeric system that only uses two digits - 0 and 1. And if we talk about how it works on the computer then. Computers operate in binary, it means they store data in binary form. So it is important because multiple binary digits can be used to represent large numbers and perform complex problems.

Base -> 2

Example:- 

 10101010101

What is Decimal? 

A decimal number is widely used in computer applications and computer applications created by the code or programming language. Decimal is also called the base 10 number system. And it consists of 10 digits, e.g:- 1,2,3,4,5,6,7,8,9 each digits has a decimal system.

Base -> 10

Example:-

     34

Approach: 

We will enter a binary value and the output will come to its decimal conversion digit. So we need to write a program that converts input binary value into decimal. So in this program, we will use:-

Example:

Input Binary Value: 1000001

Output Decimal value: 65 

Code

b_num = list(input("Input a binary number: "))
value = 0

for i in range(len(b_num)):
	digit = b_num.pop()
	if digit == '1':
		value = value + pow(2, i)
print("The decimal value of the number is", value)

Output:

Input Binary Value: 1000001

Output Decimal value: 65 
 
190 points
4