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!

Trying to convert hex string to int

807599Jan 5 2007 — edited Jan 5 2007
I'm trying to convert an input hex string to an into to set a color value. I've tried two different approaches, neither of which works. I get nothing but zero no matter what string I input. What am I doing wrong?

First approach:
String hexValue = "ff0000";
Integer intObject = new Integer(0);
intObject.parseInt(hexValue,16);
colorValue = intObject.intValue();
System.out.println("hexValue = "+hexValue+"   Color value = "+colorValue);

Output:  hexValue = ff0000   Color value = 0
Second approach:
String hexValue = "0xff0000);
Integer intObject = new Integer(0);
intObject.decode(hexValue);
colorValue = intObject.intValue();
System.out.println("hexValue = "+hexValue+"   Color value = "+colorValue);

hexValue = 0xff3333   Color value = 0
thanks,

--gary
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 2 2007
Added on Jan 5 2007
2 comments
519 views