1

tl;dr - How do I convert the binary of a IEEE 754 80-bit floating point number into a Java BigDecimal or Double?


I'm writing an .aiff file parser in Java following the specification found here.

I've hit my first major roadblock with what that spec defines as the "extended" data format;

extended: 80 bit IEEE Standard 754 floating point number (Standard Apple Numeric Environment [SANE] data type Extended).

It's used once in the file to describe the sample rate of the sound (so it's pretty important).

I have no idea how to convert these 10-bytes into a Java Double or BigInteger. Double.longBitsToDouble() only allows me to use the 8-bytes of the Long type and BigDecimal lacks any methods for interpreting byte arrays.


Then again, I am assuming I'm supposed to receive a number akin to 48khz or 44.1khz. Here's some debug output from my program;

Parsing AIFF File (foo.aif)
[Header: FORM, 6461086 bytes]
[Header: COMT, 410 bytes]
[Header: COMM, 18 bytes]
Sample rate: 3.025021223671622E23
[Header: CHAN, 32 bytes]
[Header: SSND, 6460590 bytes]

Where I attempt to calculate the the sample rate using the suggestion from here (I doubted it would work);

byte[] sampleRateBytes = new byte[10];
inputStream.read(sampleRateBytes);
BigInteger intermediateRep = new BigInteger(sampleRateBytes);
sampleRate = new BigDecimal(intermediateRep);
Community
  • 1
  • 1
Foodstuff
  • 43
  • 1
  • 5
  • 1
    Java doesn't have an 80-bit floating point type. You'll have to either find a library that does that (that question is off-topic here) or write your own code to interpret the various bit fields in the 80-bit float. 64-bit format has an 11-bit exponent, while 80-bit format has a 15-bit exponent. This shouldn't be that hard to do. – Jim Garrison Mar 28 '17 at 06:21
  • 1
    See also: [x86 80-bit floating point type in Java](http://stackoverflow.com/q/33419039/5221149) – Andreas Mar 28 '17 at 06:41

0 Answers0