Integer.parseInt("ff8ca87c", 16);
This gives me a NumberFormatException for some reason. Do you know why that is?
Exception in thread "main" java.lang.NumberFormatException: For input string: "ff8ca87c"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.valueOf(Unknown Source)
The reason it fails is that you’re trying to put
+0xff8ca87cinto a signed integer. The maximum value of a 32-bit signed integer is+0x7fffffff, because the most significant bit is used to store the sign.Try using a
longinstead. The maximum value of a 64-bit signed int is0x7fffffffffffffff, which is more than adequate for your needs in this case.Or, in Java 8 you can use
Integer.parseUnsignedInt("ff8ca87c", 16);which will treat the value as an unsigned integer.