float f = 8.69f;
int a = Float.floatToIntBits(f);
String floatStr = Integer.toBinaryString(a);
double d1 = f;
long b = Double.doubleToLongBits(d1);
String convertStr = Long.toBinaryString(b);
double d2 = 8.69;
long c = Double.doubleToLongBits(d2);
String doubleStr = Long.toBinaryString(c);
System.out.println(floatStr);
System.out.println(convertStr);
System.out.println(doubleStr);
输出是:
1000001000010110000101000111101 100000000100001011000010100011110100000000000000000000000000000 100000000100001011000010100011110101110000101000111101011100001
当将float转换为double时,为什么jvm只复制float的位,然后将零添加到double的其余位,而不是像输出中的第三行那样计算实数位。