How to Convert Binary to Decimal

How to Convert Binary to Decimal

5 mins read446 Views Comment
Vikram
Vikram Singh
Assistant Manager - Content
Updated on Aug 16, 2024 12:18 IST

In this article, we will learn, what is a binary number, what is a decimal number, and how to convert binary number to decimal number with the help of different examples.

2023_07_Feature-Image-Templates-67.jpg

Computer system understands four different types of Number Systems: Binary Number System (Base-2), Octal Number System (Base-8), Decimal Number System (Base-10), and Hexadecimal Number Systems (Base-16), and converting one to another is quite tricky. So, in this article, we will discuss how to convert a Binary Number System to a Decimal Number System with the help of different examples.

Let’s start the article with the formal definition of Binary Numbers and Decimal Numbers.

Table of Content

What is a Binary Number System?

A Binary Number System is a Numerical System that uses only two digits, 0 and 1, to represent all the numbers and perform the arithmetic operations. Let’s break it down and have an example to understand better.

The Binary Number System is like a light switch: It can only be in one of the two states, either on or off. In binary, these states are represented by the digits 0 (Off) and 1 (On). For example, the binary number 101 represents a pattern of on-off-on.

Each digit, known as a bit (short for binary digit), represents a power of 2 in the binary system. 

The rightmost bit represents 20

The next bit to the left represents 21

Next represents 22

And so on.

Note: Each bit’s value can be either 0 or 1, indicating the absence or presence of that power of 2, respectively.

Please check the top online maths for data science courses 

Explore the best online statistics courses for data science

Recommended online courses

Best-suited IT & Software courses for you

Learn IT & Software with these high-rated online courses

18 K
1 year
39.88 K
2 years
– / –
2 years
18 K
1 year
10.8 K
6 months
– / –
2 years
16.25 K
4 weeks
19.5 K
12 months
name
ICACertificate
– / –
80 hours

What is a Decimal Number System?

The Decimal Number System (also known as the base-10) is a numerical system that is commonly used in our day-to-day life. The position of each digit in the decimal number determines its values. The rightmost position is known as the unit place, followed by the tens place, hundred places, and so on, i.e., each position to the left represents an increasing power of ten.

Let’s understand it in very layman’s terms.

The decimal Number System is like counting a number of your fingers. It has ten digits, from 0 to 9, just like you have ten fingers. When you run out of fingers to count on, you start over and keep track of how many times you’ve done so.

For example, the Number 123, in decimal, means you have counted to 10 twelve times and then counted an additional 3.

What are the Different Methods to Convert Binary to Decimal?

Mainly there are two different methods to convert Binary to Decimal:

  • Positional Notation
  • Doubling Method

Positional Notation

Step-1: Write Down the Binary Number and List the Power of 2 from the Right to Left.

  • The value at the rightmost starts with 20, followed by 21 , 22 , …..
  • For Example, the Number 11011 has 5 digits, so the number would look like 16, 8, 4, 2, 1.
2023_07_Slide1-2.jpg

Step-2: Multiply Each Digit in the Binary Number Starting from the right with its respective weights (exponents form-2n).

2023_07_Slide2-1.jpg

Step-3: Add the final values.

Here, (11011)₂ = (1 × 2⁴) + (1 × 2³) + (0 × 2²) + (1 × 2¹) + (1 × 2⁰) = (27)₁₀

2023_07_Slide3.jpg

Doubling Method

This method doesn’t use powers of two. It is simpler than Positional Notation; you have to start from the left, double the previous total, and add the current digit.

Confused!! Don’t worry. Here is a step-by-step explanation.

  • Step-1: Write the given binary number and start from the left. Double the previous value and add the current digit. 

Note: Since we are starting from the left-most digit, there will be no previous digit, so in this case, double the previous digit will be considered as 0.

For example, in 11011, the left-most digit is 1, then the double of the previous digit will be 0. Therefore, we will get ((0 * 2) + 1) = 0 + 1 = 1.

  • Step-2: Continue the process till the last digit (right-most digit). Once you reach the last digit, the sum will be the decimal value corresponding to the given binary number.

Now, let’s have the same above example and find its decimal value using the doubling method.

2023_07_Slide4-1.jpg

Till now, you have a clear understanding of how to convert Binary Number into a Decimal Number. Now, it’s time to level up. Let’s see how it this can be done with the help of programming languages like Python, C, and Java.

How to Convert Binary to Decimal in Python


 
# Binary to Decimal Conversion
# Define the binary number
binary_number = "10101"
# Initialize the decimal variable
decimal_number = 0
# Calculate the decimal value
# Start from the rightmost digit of the binary number
# and move towards the left, multiplying each digit by the appropriate power of 2
# and adding it to the decimal number
# Iterate through each digit of the binary number
for i in range(len(binary_number)):
# Get the current digit
digit = int(binary_number[i])
# Calculate the power of 2 for the current digit
power = len(binary_number) - i - 1
# Calculate the decimal value of the current digit
decimal_value = digit * (2 ** power)
# Add the decimal value to the total decimal number
decimal_number += decimal_value
# Print the binary and decimal numbers
print("Binary number:", binary_number)
print("Decimal number:", decimal_number)
Copy code

Output

2023_07_how-to-convert-binary-to-decimal-in-python-1.jpg

How to Convert Binary to Decimal in Java


 
public class BinaryToDecimal {
public static void main(String[] args) {
// Binary to Decimal Conversion
// Define the binary number
String binaryNumber = "111000";
// Initialize the decimal variable
int decimalNumber = 0;
// Calculate the decimal value
// Start from the rightmost digit of the binary number
// and move towards the left, multiplying each digit by the appropriate power of 2
// and adding it to the decimal number
// Iterate through each digit of the binary number
for (int i = binaryNumber.length() - 1; i >= 0; i--) {
// Get the current digit
int digit = Character.getNumericValue(binaryNumber.charAt(i));
// Calculate the power of 2 for the current digit
int power = binaryNumber.length() - i - 1;
// Calculate the decimal value of the current digit
int decimalValue = digit * (int) Math.pow(2, power);
// Add the decimal value to the total decimal number
decimalNumber += decimalValue;
}
// Print the binary and decimal numbers
System.out.println("Binary number: " + binaryNumber);
System.out.println("Decimal number: " + decimalNumber);
}
}
Copy code

Output

2023_07_how-to-convert-binary-to-decimal-in-java.jpg

How to Convert Binary to Decimal in C


 
#include <stdio.h>
#include <math.h>
int main() {
// Binary to Decimal Conversion
// Define the binary number as a string
char binaryNumber[] = "101101";
// Calculate the length of the binary number
int length = strlen(binaryNumber);
// Initialize the decimal variable
int decimalNumber = 0;
// Calculate the decimal value
// Start from the rightmost digit of the binary number
// and move towards the left, multiplying each digit by the appropriate power of 2
// and adding it to the decimal number
// Iterate through each digit of the binary number
for (int i = length - 1, power = 0; i >= 0; i--, power++) {
// Get the current digit
int digit = binaryNumber[i] - '0';
// Calculate the decimal value of the current digit
int decimalValue = digit * pow(2, power);
// Add the decimal value to the total decimal number
decimalNumber += decimalValue;
}
// Print the binary and decimal numbers
printf("Binary number: %s\n", binaryNumber);
printf("Decimal number: %d\n", decimalNumber);
return 0;
}
Copy code

Output

2023_07_how-to-convert-binary-to-decimal-in-c.jpg

Please Explore Our Other Blogs on Mathematics and Statistics for Data Science

Sum of GP Formula

Ultimate Guide to the GP Formula: Understanding its Impact and Utility

How to Find the Inverse of a Matrix?

Lower Triangular Matrix: Definition, Example, and Properties

Upper Triangular Matrix: Definition, Example, and Properties

How to Calculate the Determinant of a Matrix?

Diagonal Matrix: Definition, Example, and Properties

Identity Matrix: Definition, Examples, and Properties

Square Matrix Fundamentals: A Quick Guide

All About Logarithmic Functions

The Chain Rule: Formula and Examples

FAQs

What is Binary Number System?

A Binary Number System is a Numerical System that uses only two digits, 0 and 1, to represent all the numbers and perform the arithmetic operations.

What is Decimal Number System?

The Decimal Number System (also known as the base-10) is a numerical system that is commonly used in our day-to-day life. The position of each digit in the decimal number determines its values. The rightmost position is known as the unit place, followed by the tens place, hundred places, and so on, i.e., each position to the left represents an increasing power of ten.

What are the different methods to convert binary to decimal?

Positional Notation and Doubling Methods are two methods that are used to convert binary to decimal.

About the Author
author-image
Vikram Singh
Assistant Manager - Content

Vikram has a Postgraduate degree in Applied Mathematics, with a keen interest in Data Science and Machine Learning. He has experience of 2+ years in content creation in Mathematics, Statistics, Data Science, and Mac... Read Full Bio