Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Converting Hex to Integer Value

807601Feb 11 2008 — edited Feb 11 2008
I'm trying to convert hex code to the corresponding integer, which can then be used to display a character.

For example I have the code.
int i = 0xE7;
System.out.println(i);
System.out.write(i)
This produces the output as expected with the first output outputting 231, and the second line outputting the corresponding character.

My problem comes when trying to make it so the hex code is variable.

For example, I receive an output of 7
This output is then the last digit of the hex code (so i check if needs to be converted to a, b etc.) then try and combine it with the prefix 0xE to create the hex code.
I'm not quite sure how to do this bit as I cant carry out
num = 7;
hex = "0xE"+num;
int i = hex;
as the last line doesn't calculate due to hex being a string.

Many thanks for your help.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 10 2008
Added on Feb 11 2008
10 comments
585 views