Java Convert Octal String to short

Tags: Octal short

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

How to convert octal String to short in Java

In Java, with a given octal number String we can use the Short.decode(String nm) static method to convert it to a short value as the example Java code below.

public class ConvertOctalToShortExample1 {
    public static void main(String... args) {
        String octalValue1 = "0100";
        String octalValue2 = "0200";

        // Convert octal String to short
        short shortValue1 = Short.decode(octalValue1);
        short shortValue2 = Short.decode(octalValue2);

        System.out.println("octalValue1: " + octalValue1);
        System.out.println("shortValue1: " + shortValue1);
        System.out.println("\noctalValue2: " + octalValue2);
        System.out.println("shortValue2: " + shortValue2);
The output as below.
octalValue1: 0100
shortValue1: 64

octalValue2: 0200
shortValue2: 128

Happy Coding 😊

Java Convert short to Octal String

Java Convert Octal String to Integer

Java Convert Integer to Octal String