Java Convert Integer to Binary String

Tags: Integer Binary

In this Java core tutorial we learn how to convert an Integer value into a binary String in Java programming language.

How to convert Integer to binary String in Java

In Java, with a given Integer value we can use the Integer.toBinaryString(int i) static method to convert it to a binary String in base 2 as the example Java code below.

ConvertIntegerToBinaryStringExample.java

public class ConvertIntegerToBinaryStringExample {
    public static void main(String... args) {
        int intValue = 999999;

        // Convert Integer to Binary String
        String binaryString = Integer.toBinaryString(intValue);

        System.out.println("int value: " + intValue);
        System.out.println("binary string: " + binaryString);
    }
}
The output as below.
int value: 999999
binary string: 11110100001000111111

Happy Coding 😊

Java Convert short to Binary String

Java Convert Long to Binary String