Convert decimal to binary in java

In this post, we will see how to convert decimal to binary in java.

There are lot of ways to convert decimal to binary in java.Let’s explore them one by one.


Using Integer.toBinaryString() method

You can simply use inbuilt Integer.toBinaryString() method to convert a decimal

Output:

Binary representation of 12 : 1100
Binary representation of 32 : 100000
Binary representation of 95 : 1011111

Using iterative array approach

Output:

Enter a decimal number
12
Binary representation is : 1100

Using stack

Output:

Enter decimal number:
32
Binary representation is : 100000

That’s all convert decimal to binary in java.

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *