Home » Python program to convert Binary to Decimal

Python program to convert Binary to Decimal

Learn about the Python program to convert Binary to Decimal in the below code example. Also, refer to the comments in the code snippet to get a detailed view about what’s actually happening.

A binary number is a number stated in the base-2 numeric system, often known as the binary numeral system, which employs only two symbols, 0 and 1.

The decimal numeral system is the most widely used system for representing both integer and non-integer values.

Python program to convert Binary to Decimal

To convert binary values to decimals, we can utilise the built-in int() method. The int() method translates a binary text to an integer in base 2.

Program:

# Python program to convert Binary to Decimal

def BinaryDecimal(n):
    return int(n, 2)
 
# inputs from user
num = input('Enter a binary number: ')

# print result
print('The decimal value is =', BinaryDecimal(num))

Output:

Enter a binary number: 0110
The decimal value is = 6

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Code : Binary to Decimal in Python Program