I wanted to convert integer values to hex strings. I quickly searched stackoverflow and did it the following way (as the accepted solution indicated - however didn't look careful enough):
Integer.valueOf(String.valueOf(n), 16);
However when trying to convert
Integer.valueOf(String.valueOf(-2115381772), 16)
it throws an NumberFormatException
. So out of curiosity - why is the NumberFormatException thrown?
(Afterwards I changed the code to Integer.toHexString(-2115381772)
and everything is working as expected.)