74
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.
Output:
1010 10101 11111
Java Decimal to Binary conversion: Custom Logic
We can convert decimal to binary in java using custom logic.
Output:
Decimal of 10 is: 1010 Decimal of 21 is: 10101 Decimal of 31 is: 11111
Next TopicJava Hex to Decimal