import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
public class TestMain {
public static void main(String[] args) throws IOException {
TestMain test = new TestMain();
double value = 12111113.11111;
//将double类型数据转成二进制数据
String str_value = Long.toBinaryString(Double.doubleToRawLongBits(value));
InputStream in = new ByteArrayInputStream(str_value.getBytes());
try {
double v = test.readDouble(in);
System.out.println(v);
} finally {
in.close();
}
}
private double readDouble(InputStream in) throws IOException {
//1个double的二进制字节码有64位
byte[] tmp = new byte[8 * 8];
int read = 0;
if (in != null && ((read = in.read(tmp)) != -1)) {
String str_value = new String(tmp, 0, read);
return Double.longBitsToDouble(Long.parseLong(str_value, 2));
}
return -1;
}
}