To convert an integer to binary, use the Integer.toBinaryString() method in Java.
Let’s say the following is the integer we want to convert.
int val = 999;
Converting the above integer to binary.
Integer.toBinaryString(val)
public class Demo { public static void main(String[] args) { int val = 999; // integer System.out.println("Integer: "+val); // binary System.out.println("Binary = " + Integer.toBinaryString(val)); } }
Integer: 999 Binary = 1111100111