The conversion of the int to binary runs correctly, but the reverse operation (binary string to int) throws an NumberFormatException.
String binIntStr = Integer.toBinaryString(-1610612462); System.out.println("Binary : "+binIntStr); System.out.println("Int : "+Integer.parseInt(binIntStr, 2));
I'd like that someone of Sun explains to me if it'sSun employees don't generally post here. Most of us who answer questions here do not work for Sun. You probably won't get an answer from Sun.
normal or not.
toBinaryStringso you will have to figure out out to deal with signed values yourself
public static String toBinaryString(int i)Returns a string representation of the integer argument as an unsigned integer in base 2.
The unsigned integer value is the argument plus 232 if the argument is negative; otherwise it is equal to the argument.
This value is converted to a string of ASCII digits in binary (base 2) with no extra leading 0s. If the unsigned magnitude is zero, it is represented by a single zero character '0' ('\u0030');
otherwise, the first character of the representation of the unsigned magnitude will not be the zero character. The characters '0' ('\u0030') and '1' ('\u0031') are used as binary digits.
i - an integer to be converted to a string.
the string representation of the unsigned integer value represented by the argument in binary (base 2).