I came across this topic looking for the same code. Here is what I wrote:
public static byte [] Double2Real48(double d) { byte [] r48 = new byte[6]; byte [] da = BitConverter.GetBytes(d); for (int i = 0; i < r48.Length; i++) r48[i] = 0;
Real48 is similar to IEEE 754 in that Mantissa will be the same. A bit shift is needed to get Mantis in the right place.
Real48 has an offset of 129, and a double has an offset of 1023.
A negative flag is stored in the first bit of the last byte.
Notes: I do not think this code will work on a large destination machine. It does not check for NAN or INF.
Here is the code that converts real48 to double. It was ported from the Free Pascal compiler:
static double real2double(byte [] r) { byte [] res = new byte[8]; int exponent;
source share