I'm looking for code that will take a 64-bit double in visual studio and convert it to a 80-bit extended (IEEE-754) double. The result should be stored in a 10 byte array (in little endian format I imagine). The reason is that I need to send the 80-bit double to a program which was written in Borland c++ and asks for this double. But I don't know how to do this since what I tried (basically taking the mantissa and exponent which are 52 and 11 bits respectively, converting the exponent so that it's 16383 offset in 15 bits and padding the mantissa to 64 bits) didn't seem to work. It is the inverse of this question.
inline void ConvertDblToLongDbl(double dbl, unsigned char aCh[10])
{
__int64 ull= *(__int64*)(&dbl);
*(unsigned short*)&aCh[8]= (unsigned short)((ull>>52&0x7FF+15360)| // exponent, from 11 bits to 15 bits
((ull&(__int64)1<<63)?0x8000:0)); // sign, the 16th bit
ull= ull&0xFFFFFFFFFFFFF;
*(__int64*)&aCh[0]= ull|0x8000000000000000;
}
Thanks,
M