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);