Java Convert short to Binary String

Tags: short Binary

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

How to convert short to binary String in Java

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

ConvertShortToBinaryStringExample.java

public class ConvertShortToBinaryStringExample {
    public static void main(String... args) {
        short shortValue = 123;

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

        System.out.println("short value: " + shortValue);
        System.out.println("binary string: " + binaryString);
    }
}
The output as below.
short value: 123
binary string: 1111011

Happy Coding 😊

Java Convert Integer to Binary String

Java Convert Long to Binary String