The following method throws a RuntimeException when rawValue is something like 0xFFFF0000
This is because Integer.parseInt not designed to handle the 0x prefix.
I tried using Integer.decode (String), but that throws a NumberFormatException, although the grammar seems to be correct.
From Integer.decode Javadoc (related in your question):
This character sequence must be a positive value or a NumberFormatException will be thrown.
0xFFFF0000 is a negative number, and therefore, this probably causes the reason for the exception here.
Decision:
If you know that the specified value will be in the form 0x[hexdigits] , you can use Integer.parseInt(String, int) , which takes a radix value. For hexadecimal, the radix is ββ16. Like so:
return Integer.parseInt(rawValue.split("[x|X]")[1], 16);
This uses regex [x|X] to split the string, which will separate rawValue in lower or upper case of the character "x", and then passes it to parseInt with a radius of 16 for parsing it in hexadecimal format.
Brian source share