hex to char conversion problem...

hello,

I have a a following piece of code, where I am trying to conver 0x72 to character 'r' :

String hexStr ="0x72";

String charString =new Character((char)Integer.parseInt(hexStr, 16)).toString();

I am getting following exception:

java.lang.NumberFormatException: For input string:"0x72"

at java.lang.NumberFormatException.forInputString(Unknown Source)

at java.lang.Integer.parseInt(Unknown Source)

Am I doing something wrong?

Any help will be appreciated...

Thanks!

[666 byte] By [dd007007a] at [2007-10-3 4:49:11]
# 1

Integer.parseInt just wants numbers. The leading "0x" isn't technically part of the hex format number. Keep in mind that a person could decode something base 36 and the x would part of the number.

However, I believe that Integer.decode is smart enough to figure out the 0x and skip it. Try using that.

Also I think java.util.Scanner knows how to work with hex numbers signified with a leading 0x.

paulcwa at 2007-7-14 22:53:41 > top of Java-index,Java Essentials,Java Programming...