0

taking in account that FFFFFFB2 in HEX is -78 in decimal

Why I have an error with this operacion ?

Integer.parseInt("FFFFFFB2", 16)

Error:

Exception in thread "main" java.lang.NumberFormatException: For input string: "FFFFFFFFFFFFFFB2"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:495)
    at tmp.Test.main(Test.java:11)
1
  • 1
    Did you know that the number you are trying to convert is a huge number and is equivalent to 18446744073709552000 in decimal? Commented Jan 23, 2016 at 14:22

2 Answers 2

1

taking in account that FFFFFFFFFFFFFFB2 in HEX is -78 in decimal"

Nope, FFFFFFFFFFFFFFB2 hex is 18446744073709552000 decimal. You're mistaking hex for 2s complement.

If you want to take a 2s complement bit pattern and convert it into a number, this answer suggests a trick:

long l = new BigInteger("FFFFFFFFFFFFFFB2",16).longValue();

And it actually works.

Note I used BigInteger and long, rather than long and int, as the number is too big.

Sign up to request clarification or add additional context in comments.

Comments

0

According to the documentation:

An exception of type NumberFormatException is thrown if any of the following situations occurs:

The value represented by the string is not a value of type int.

As already pointed out, your number is not an int.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.