今天春天
今天春天

Reputation: 993

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'.

Upvotes: 2

Views: 3020

Answers (2)

今天春天
今天春天

Reputation: 993

This did it for me:

int octalValue = 123;
String abc = Integer.toString(octalValue);
char abcChar = (char) Integer.parseInt(abc, 8);

Better solutions might be out there.

Upvotes: 1

assylias
assylias

Reputation: 328598

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

Upvotes: 3

Related Questions