I'm trying to开发者_JAVA百科 parse into int
a String
which is hexadecimal number in my code (FF00FF00, for example) using Integer.parseInt(String string, int radix)
, but always get NumberFormatException
. If I parse the number without last two numbers (FF00FF) it works well.
Is there any method to parse such big numbers in Java?
If Integer is too small, use Long
:
Long.parseLong(string, 16)
If Long is still too small, use BigInteger
:
new BigInteger(string, 16)
I would use Long.parseLong(x, 16)
BigInteger is overkill for a 32-bit value.
If you expect this value to be an int value you can cast the result.
int x = (int) Long.parseLong("FF00FF00", 16);
精彩评论