title: Convert 64-bit double to 80-bit double in byte array form in visual studio
body: <p>I'm looking for code that will take a 64-bit double in visual studio and convert it to a <a href="https://en.wikipedia.org/wiki/Extended_precision#IEEE_754_extended_precision_formats" rel="nofollow noreferrer">80-bit extended (IEEE-754)</a> 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 <a href="https://stackoverflow.com/questions/2963055/msvc-win32-convert-extended-precision-float-80-bit-to-double-64-bit">this question</a>.</p>
  
  <pre><code>inline void ConvertDblToLongDbl(double dbl, unsigned char aCh[10])
  {
  __int64 ull= *(__int64*)(&amp;dbl);
      *(unsigned short*)&amp;aCh[8]= (unsigned short)((ull&gt;&gt;52&amp;0x7FF+15360)|  //     exponent, from 11 bits to 15 bits
          ((ull&amp;(__int64)1&lt;&lt;63)?0x8000:0));   // sign, the 16th bit
      ull= ull&amp;0xFFFFFFFFFFFFF;
      *(__int64*)&amp;aCh[0]= ull|0x8000000000000000;
  }
  </code></pre>
  
  <p>Thanks,<br>
  M</p>