Convert 80 bit enhanced precision to java

I am working on a program that converts really old Open Access 4..df files to other formats, as well as creating database scripts - I can already convert every possible type except decimal. I found out that the byte order should be 80 bit extended precision. I already tried to do the conversion myself, but I was not able to do the conversion from 80-bit extended precision ( https://en.wikipedia.org/wiki/Extended_precision#x86_Extended_Precision_Format ) to String and String to 80-bit extended precision in Java.

  • Example:

Value: 1,235

Hex from df File: 40 00 9e 06 52 14 1e f0 db f6

  1. Example:

Value: 0.750

Hex from df File: 3f ff c0 00 00 00 00 00 00 00

Can someone help with the conversion?

Regards

@EJP comment: Well, I throw away the last 16 bits, so I got 3f ff c0 00 00 00 00 relative to ( Java - Convert hex to IEEE-754 64-bit float - double precision ) I'm trying to convert it using

String hex = "3fffc00000000000";
long longBits = Long.valueOf(hex ,16).longValue();
double doubleValue = Double.longBitsToDouble(longBits);

But the result is 1.984375, not 0.750

+4
source share
1 answer

I'm not sure if it matches as an answer, or is it possible to answer at all, because ... are you sure this is a standard 80-bit floating point format? Because it is, it looks a little strange. Take the first example:

40 00 9e ...

0x4000-16383 = 1 . MSB 1, , 1,... x 2 ^ 1, 2. , 1235. .

Java, double:

long high = 0x40_00L;
long low = 0x9e_06_52_14_1e_f0_db_f6L;
long e = (((high & 0x7FFFL) - 16383) + 1023) & 0x7FFL;
long ld = ((high & 0x8000L) << 48)
          | (e << 52)
          | ((low >>> 11) & 0xF_FFFF_FFFF_FFFFL);
System.out.printf("%16X\n", ld);
double d = Double.longBitsToDouble(ld);
System.out.println(d);

, 80- , , , , , , , , NaN.

4003C0CA4283DE1B
2.46913578

1,235! ++ ( GCC, long double 80- ):

#include <stdio.h>

int main() {
    long long high = 0x4000;
    long long low = 0x9e0652141ef0dbf6;
    long double d;
    char *pd = (char*)&d, *ph = (char*)&high, *pl = (char*)&low;
    for (int i = 0; i < 8; ++i) {
        pd[i] = pl[i];
    }
    for (int i = 0; i < 2; ++i) {
        pd[8 + i] = ph[i];
    }
    printf("%lf\n", (double) d);
}

2.469136.

+3

All Articles