English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Convert Decimal to Binary in Java

Use the Integer.toBinaryString() method to convert Decimal to Binary in Java.

First, set a decimal value.

int val = 300;

Now, use the Integer.toBinaryString() method to convert the given decimal value above.

String res = Integer.toBinaryString(val);

Let's see the complete example.

Example

public class Demo {
   public static void main( String args[] ) {
      int val = 300;
      System.out.println("Decimal = ",+val);
      String res = Integer.toBinaryString(val);
      System.out.println("Binary = ",+res);
   }
}

Output Result

Decimal = 300
Binary = 100101100