Short solution - Integers simply don't go that high. That's not an int.
ParseInt()
documentation mentions, you recieve a string and a radix, and get back the result of the convertion. However, integers are 4 bytes = 32 bits, and thus range from -(2^31)
to 2^31-1
, and your number - 11011111110111000001110000111110
, is in fact 32 bits long - which means, it's bigger than the maximal value. Thus, the function throws this NumberFormatException
- this is not a valid value for an int.
If you'd like to fix it, I'd use a ByteBuffer
, like described here:
ByteBuffer buffer = ByteBuffer.wrap(myArray);
buffer.order(ByteOrder.LITTLE_ENDIAN); // if you want little-endian
int result = buffer.getShort(); // use with a bigInteger instead. you could use any of the bytebuffer functions described in the link :)