I'm trying to convert a couple of binary strings back to int. However it doesn't convert all my binary strings, leaving me a java.lang.NumberFormatException exception.
Here is my test code with 3 binary string:
public class Bin {
public static void main(String argvs[]) {
String binaryString ;
binaryString = Integer.toBinaryString(~0);
//binaryString = Integer.toBinaryString(~1);
//binaryString = "1010" ;
int base = 2;
int decimal = Integer.parseInt(binaryString, base);
System.out.println("INPUT=" + binaryString + " decimal=" + decimal) ;
}
}
If I convert the "1010" it works great, but when I try to convert one of the other two I get the exception. Can someone explain to me why this is ?
Cheers
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…