String ret = Integer.toBinaryString(-5);
System.out.println(ret);
DecimalFormat df = new DecimalFormat ("00000000,00000000,00000000,00000000");
System.out.println(df.format(Integer.valueOf(ret)));
出现异常如下:
11111111111111111111111111111011
Exception in thread "main" java.lang.NumberFormatException: For input string: "11111111111111111111111111111011"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.valueOf(Unknown Source)
at com.develop.bit.TestBitCalculate.main(TestBitCalculate.java:60)
但如果把Integer.valueOf改成Double.valueOf,异常就没有了,但输出的值很奇怪。如下:
11111111111111111111111111111011
11111111,11111111,20000000,00000000
求解!谢谢。
|
|