Search code examples
javastringdecimaloctal

Octal to text in Java


I have a integer:

int octalValue = 103

I want to convert this to text in Java. How can I do this? The expected output would be 'C'.


Solution

  • Octal literals need to be prefixed with a 0:

    int octalValue = 0103; //89
    

    You can then convert it to the corresponding ASCII code:

    char c = (char) octalValue; //C