In a second glance, the method sent in response to converting C # double to Delphi Real48 clears very well.
For future reference:
/** * Convert a PHP number [Int|Float] to a Turbo Pascal 48-bit (6 byte) real byte representation * @param float number to convert * @return binary 48-bit real */ function doubleToReal48($double) { $byteArray = array_values( unpack('C*', pack('d', $double)) ); // 64 bit double as array of integers $real48 = array(0, 0, 0, 0, 0, 0); // Copy the negative flag $real48[5] |= ($byteArray[7] & 128); // Get the exponent $n = ($byteArray[7] & 127) << 4; $n |= ($byteArray[6] & 240) >> 4; if ($n == 0) { // Zero exponent = 0 return pack('c6', $real48[0], $real48[1], $real48[2], $real48[3], $real48[4], $real48[5]); } $real48[0] = $n - 1023 + 129; // Copy the Mantissa $real48[5] |= (($byteArray[6] & 15) << 3); // Get the last 4 bits $real48[5] |= (($byteArray[5] & 224) >> 5); // Get the first 3 bits for ($b = 4; $b >= 1; $b--) { $real48[$b] = (($byteArray[$b+1] & 31) << 3); // Get the last 5 bits $real48[$b] |= (($byteArray[$b] & 224) >> 5); // Get the first 3 bits } return pack('c6', $real48[0], $real48[1], $real48[2], $real48[3], $real48[4], $real48[5]); }
source share