Java - Convert an octal value to its corresponding ASCII value

By xngo on February 27, 2019

Convert from octal(base 8) to decimal(base 10) and then to character.

public class OctalToAscii
{
    public static void main(String[] args){
        // Note: octal is base 8.
        String sOctal = "355";
 
        // Convert Octal(base8) to decimal(base 10).
        Integer iOctal = Integer.parseInt(sOctal, 8);
        System.out.println(iOctal); // Output: 237
 
        // Cast decimal to its corresponding ASCII value.
        char cOctal = (char)iOctal.intValue();
        System.out.println(cOctal); // Output í
    }
}

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.