Java Convert Integer to Binary String
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);
}
}
int value: 999999
binary string: 11110100001000111111
Happy Coding 😊