3

In my code I have

int i = Integer.parseInt("f8004896",16);

when I run the program it throws a NumberFormatException

java.lang.NumberFormatException: For input string: "f8004896"

What am I doing wrong? This seems relatively straightforward but its not working.

Neil Locketz
  • 4,228
  • 1
  • 23
  • 34

2 Answers2

3
long i = Long.parseLong("f8004896", 16);
System.out.println(i);
System.out.println(Integer.MAX_VALUE);

Output:

4160768150
2147483647
DmitryKanunnikoff
  • 2,226
  • 2
  • 22
  • 35
1

Decimal value for f8004896 is 4160768150 and it's more than 2^31-1 (upper limit for int type). So you should use long instead: Long.parseLong()

DmitryKanunnikoff
  • 2,226
  • 2
  • 22
  • 35
nikis
  • 11,166
  • 2
  • 35
  • 45