Java Program to convert an integer into binary


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)

Example

 Live Demo

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));
    }
}

Output

Integer: 999
Binary = 1111100111

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 26-Jun-2020

8K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements