I want to parse an String containing 8 hex-digits (4bytes) but i got an NumberFormatException. What is wrong here?
assertThat(Integer.parseInt("FFFF4C6A",16),is(0xFFFF4C6A));
Your number represents a number greater than that assignable to an int. Try:
Long.parseLong("FFFF4C6A", 16);
which gives 4294921322.
From the doc:
An exception of type
NumberFormatExceptionis thrown if any of the following situations occurs:
- The first argument is null or is a string of length zero.
- The radix is either smaller than
Character.MIN_RADIXor larger thanCharacter.MAX_RADIX.- Any character of the string is not a digit of the specified radix, …
- The value represented by the string is not a value of type int.
and it's the 4th case that you're hitting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With