Java Convert Long to Binary String
In this Java core tutorial we learn how to convert a long value into binary String in Java programming language.
How to convert Long to Binary String in Java
In Java, with a given long value we can use the Long.toBinaryString(long i) static method to convert it to a binary String as the following example Java program.
ConvertLongToBinaryExample.java
public class ConvertLongToBinaryExample {
public static void main(String... args) {
long longValue = 999999;
// Convert Long to Binary String
String binaryString = Long.toBinaryString(longValue);
System.out.println("Long value: " + longValue);
System.out.println("Binary value: " + binaryString);
}
}
Long value: 999999
Binary value: 11110100001000111111
Happy Coding 😊