public static byte[] double2Bytes(double d) {
long value = Double.doubleToRawLongBits(d);
byte[] byteRet = new byte[8];
for (int i = 0; i < 8; i++) {
byteRet[i] = (byte) ((value >> 8 * i) & 0xff);
}
return byteRet;
}
public static void main(String[] args) {
double b=-10.6;
System.out.println(ByteConvertUtil.bytes2HexString(double2Bytes(b)));
System.out.println(bytes2Double(double2Bytes(b)));
}
public static double bytes2Double(byte[] arr) {
long value = 0;
for (int i = 0; i < 8; i++) {
value |= ((long) (arr[i] & 0xff)) << (8 * i);
}
return Double.longBitsToDouble(value);
}
输出结果为:
33333333333325C0
-10.6