Java Convert Long to Binary String

Tags: long Binary

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);
    }
}
The output as below.
Long value: 999999
Binary value: 11110100001000111111

Happy Coding 😊

Java Convert short to Binary String

Java Convert Integer to Binary String