18 Aug Java Program to convert decimal to binary
The toBinaryString() method is used in Java to convert decimal to binary. The syntax is as follows:
1 2 3 |
public static String toBinaryString(int dc) |
Here, dc is the decimal value you want to convert.
Note: The toBinaryString() converts and returns binary in base 2.
Example
Following is an example to convert decimal to binary:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
public class Example { public static void main( String args[] ) { int dec = 8; System.out.println("Decimal = "+dec); System.out.println("Binary = "+Integer.toBinaryString(dec)); } } |
Output
1 2 3 4 |
Decimal = 8 Binary = 1000 |
No Comments