Javatpoint Logo
Javatpoint Logo

Java Convert Decimal to Binary

We can convert decimal to binary in java using Integer.toBinaryString() method or custom logic.

Java Decimal to Binary conversion: Integer.toBinaryString()

The Integer.toBinaryString() method converts decimal to binary string. The signature of toBinaryString() method is given below:

Let's see the simple example of converting decimal to binary in java.

Test it Now

Output:

1010
10101
11111

Java Decimal to Binary conversion: Custom Logic

We can convert decimal to binary in java using custom logic.

Test it Now

Output:

Decimal of 10 is: 
1010
Decimal of 21 is: 
10101
Decimal of 31 is: 
11111





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA