So I have this binary string (32 chars corresponding to 32 bits):
String s = "11111111110000011101110111011000";
When I try to convert it to a number, it throws a NumberFormatException:
Integer.parseInt(s,2);
Could not figure out why. Any idea? The strange thing is if I replace the first bit in the string from the left (1) with a zero bit (0), then it works. The first bit is only for indicating the sign of the number, so I should not make any overflow of 4 bytes in here, right?
=================
UPDATED QUESTION: Thanks to everyone for the answers. I got it now; basically the parseInt() method CANNOT handle the sign bit and it assumes that the sign bit just represents the value as any other bit. So now the question is how to I convert such binary string to a signed INTEGER number? I know some of you suggested I use long, but in my situation I just need it to be an int (long to explain, but you can assume that).