private static double MBFToIEEEConversionLong(byte[] byteArray) { double zero = 0; double returnValue = 0 / zero; // default return value is NAN (not a number) int exponent = (int)(byteArray[7] - 128); // most significant byte is exponent. Subtracting 128 removes MBF exponent bias. char[] littleEndian = BitConverter.ToString(byteArray).Replace("-", string.Empty).ToCharArray(); // convert byte stream to ASCII hex characters UInt64 floatSign = 0x8000000000000000; // this will be all zeros if the sign proves to be positive, otherwise the IEEE sign bit is set switch (littleEndian[12]) { case '8': case '9': { littleEndian[12] -= (char)8; // ascii '8' becomes ascii '0', ascii '9' becomes ascii '1' break; } case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': { littleEndian[12] -= (char)15; // ascii 'A' becomes ascii '2', ascii 'F' becomes ascii '7' break; } default: { floatSign = 0; break; } } // in following statement, byte order is reversed, however character order within each byte is preserved string mbfMantissa = string.Empty + littleEndian[12] + littleEndian[13] + littleEndian[10] + littleEndian[11] + littleEndian[8] + littleEndian[9] + littleEndian[6] + littleEndian[7] + littleEndian[4] + littleEndian[5] + littleEndian[2] + littleEndian[3] + littleEndian[0] + littleEndian[1]; long mantissa = Convert.ToInt64(mbfMantissa, 16); // 16 indicates we're converting hex digits. if (mantissa == 0) return 0; // if there are no one bits in the mantissa the entire variable is zero long maskedMantissa = mantissa & 0x80000000000000; while (maskedMantissa == 0) // normalizing mantissa. MBF variables aren't automatically normalized during assignments { mantissa += mantissa; // shifts value to left (multiply by 2) exponent -= 1; //adjusts exponent in the reverse direction (effectivily divides by 2) maskedMantissa = mantissa & 0x80000000000000; } mantissa += mantissa; // this pushes the 'implied 1 bit' off the left end exponent -= 1; //adjusts exponent in the reverse direction (effectivily divides by 2) mantissa &= 0xFFFFFFFFFFFFF0; // masks off leading bit and any trailing digits (52 bit mantissa); mantissa /= 16; // shift mantissa to the right 4 bits exponent += 1023; // add IEEE bias UInt64 exponentComponent = (UInt64)exponent * 0x10000000000000; // shifts the exponent to it's appropriate displacement UInt64 condensate = floatSign | exponentComponent | (UInt64)mantissa; // logical 'or' the sign bit, exponent, and mantissa together byte[] ieeeOut = BitConverter.GetBytes(condensate); // serialize as byte array return BitConverter.ToDouble(ieeeOut, 0); }