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:
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:
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
Decimal = 8 Binary = 1000
No Comments