Blog_Banner_Asset
    Homebreadcumb forward arrow iconBlogbreadcumb forward arrow iconSoftware Developmentbreadcumb forward arrow iconJava Program to Convert Binary to Decimal

Java Program to Convert Binary to Decimal

Last updated:
18th Feb, 2023
Views
Read Time
5 Mins
share image icon
In this article
Chevron in toc
View All
Java Program to Convert Binary to Decimal

The Binary number system is a base 2 system that consists of 0’s and 1’s. The binary numbers are well understood by computers and digital systems, hence termed as ‘machine language’. Each digit in a binary system holds the place value of the power of 2.

The decimal number system is identified by humans. It is a Base 10 numbering system, using digits from 0 to 9. Each digit in the decimal holds a place value of power of 10.

Let’s discuss how to convert binary to decimal in Java in this article. 

Importance of Binary to Decimal Conversion

The complex binary language needs conversion to a human-understandable format before it reaches the common users. Hence, we require calculation methods on how to convert binary to decimal and easily figure out what they signify.

Ads of upGrad blog

Check out our free technology courses to get an edge over the competition.

Mathematical calculation for converting binary to Decimal

Since binary numbers are base 2 numbering systems, every place holds the value 2n. For instance, the first place has a value 20 = 1, the second place has a value 21 = 2, the third place 22 = 4 and so on. 

Let’s consider an example:

Convert Binary number 101101 to decimal number:

101101

MSB                                                                                                          LSB

The number on the leftmost side is called MSB or Most Significant bit with a maximum power of 2, and the number on the Rightmost side is called LSB or Least Significant bit, with minimum power of 2.

Now, let’s see the mathematical binary decimal converter method for the following.

(101101)2

=1 x 25 + 0 x 24 + 1x 23 + 1x 22 + 0 x 21 + 1 x 20

= 32 +0 + 8 + 4 + 0+ 1

= (45)10

It seems interesting for a small binary number. But it is a difficult task to be considered while the number is really long. In such situations, we can’t depend on manual calculations, and we require a binary decimal converter.

Check Out upGrad’s Software Development Courses

Java Program to convert Binary to Decimal

Coding has its own importance in the digital era. It helps to replace the manual burden of decoding the machine language into a human-readable form. It enables a quick and efficient way of converting any binary number into a decimal number with no tedious efforts.

Let’s learn how to convert binary to decimal in Java. There are two possible methods to write a Java program to convert binary to decimal.

  1. Using ParseInt () method of class Integer
  2. User defined or custom logic method

Explore our Popular Software Engineering Courses

  • Using ParseInt () Method

In the program, two arguments are generally used. The first argument is String and the second one is the base required to convert the number. The output will be an integer that is represented by the string argument in the mentioned base.

There are two possible ways of using ParseInt () to convert binary to decimal in Java.

  • By prompting the user to enter the binary number:

Input:

Output:

Reference image: URL_beginnersbook_2014/07

In the above program, we make use of the Scanner class. Usually, we use the Scanner class in case the user input is required in the program. The Scanner class is found in the Java.util package. 

In-Demand Software Development Skills

Hence, the user is asked to provide a binary number to be converted to decimal as per the choice, and the converted output is obtained for the number provided.

  • By including the binary number in the program itself:

Input:

Output:

Reference Image: Reference_Javatpoint

In the above program, the binary numbers are included and converted decimal output is obtained for the input binary numbers.

  • User Defined logic/ Custom Logic

Input:

Output:

Reference Image: Reference_Javatpoint

The above Java program doesn’t use the ParseInt function. The program is written with user defined inputs. 

Binary numbers are most preferred and understood by modern digital and electronic machines, whereas decimal numbers are perceived by the general audience. Hence, both are necessary in the current world. 

Ads of upGrad blog

Read our Popular Articles related to Software Development

The quick and effortless conversion of binary to decimal in Java saves the time and reduces the burden of calculating it manually.

At upGrad, we understand the importance of practical, hands-on learning – especially when it comes to software development. As a result, our courses and training initiatives have practicality at their very core. One such initiative is Full Stack Development Bootcamp which will help you develop all the relevant skills required to excel in full-stack development. 

Profile

Pavan Vadapalli

Blog Author
Director of Engineering @ upGrad. Motivated to leverage technology to solve problems. Seasoned leader for startups and fast moving orgs. Working on solving problems of scale and long term technology strategy.

Explore Free Courses

Suggested Tutorials

View All

Suggested Blogs

Best Jobs in IT without coding
134253
If you are someone who dreams of getting into the IT industry but doesn’t have a passion for learning programming, then it’s OKAY! Let me
Read More

by Sriram

12 Apr 2024

Scrum Master Salary in India: For Freshers & Experienced [2023]
900303
Wondering what is the range of Scrum Master salary in India? Have you ever watched a game of rugby? Whether your answer is a yes or a no, you might h
Read More

by Rohan Vats

05 Mar 2024

SDE Developer Salary in India: For Freshers & Experienced [2024]
905056
A Software Development Engineer (SDE) is responsible for creating cross-platform applications and software systems, applying the principles of compute
Read More

by Rohan Vats

05 Mar 2024

System Calls in OS: Different types explained
5021
Ever wondered how your computer knows to save a file or display a webpage when you click a button? All thanks to system calls – the secret messengers
Read More

by Prateek Singh

29 Feb 2024

Marquee Tag & Attributes in HTML: Features, Uses, Examples
5133
In my journey as a web developer, one HTML element that has consistently sparked both curiosity and creativity is the venerable Marquee tag. As I delv
Read More

by venkatesh Rajanala

29 Feb 2024

What is Coding? Uses of Coding for Software Engineer in 2024
5053
Introduction  The word “coding” has moved beyond its technical definition in today’s digital age and is now considered an essential ability in
Read More

by Harish K

29 Feb 2024

Functions of Operating System: Features, Uses, Types
5124
The operating system (OS) stands as a crucial component that facilitates the interaction between software and hardware in computer systems. It serves
Read More

by Geetika Mathur

29 Feb 2024

What is Information Technology? Definition and Examples
5058
Information technology includes every digital action that happens within an organization. Everything from running software on your system and organizi
Read More

by spandita hati

29 Feb 2024

50 Networking Interview Questions & Answers (Freshers & Experienced)
5138
In the vast landscape of technology, computer networks serve as the vital infrastructure that underpins modern connectivity.  Understanding the core p
Read More

by Harish K

29 Feb 2024

Schedule 1:1 free counsellingTalk to Career Expert
icon
footer sticky close icon