title: Read from Byte Array and convert to Double
body: <p>I'm just trying to get an 8 BYTE REAL floating-point number from a BYTE array, which I've previously generated from the contents of a file, as a floating-point number.</p>
  
  <p>At the moment I know that an 8 BYTE Real is the same as a double. Therefore, it would have to be logically possible to read out the 8 bytes and assign them directly to the variable.
  Unfortunately it does not work as I imagine.</p>
  
  <p>As an illustration:</p>
  
  <p>My Byte Array Array for control output of the HEX value stored in the file.</p>
  
  <pre><code>uint64_t result = 0;
  for (int i = 0; i &lt; 8; i++){
  result = file_buf[content + i];
  wsprintf(Outbuf + i*2, L"%02X", result);
  OutputMessage(Outbuf, 0);
  }
  </code></pre>
  
  <p>Returns the correct Hex value from the file in the output</p>
  
  <pre><code>C1D6D420937EE766
  </code></pre>
  
  <p>wsprintf has to use it because I use an API work and rely on a whitecharbuffer.</p>
  
  <p>So far I have tried the following:</p>
  
  <pre><code>resdouble =  (double)*&amp;file_buf[content];
  swprintf(Outbuf, 200, L" Typ: REAL (8-byte): %Lf\n", resdouble);
  OutputMessage(Outbuf, 0);
  </code></pre>
  
  <p>Outpout:</p>
  
  <pre><code>Typ: REAL (8-byte): 193,000000
  </code></pre>
  
  <p>An other try:</p>
  
  <pre><code>result = file_buf[content]&lt;&lt;24;
  result = result + (file_buf[content + 1] &lt;&lt; 16);
  result = result + (file_buf[content + 2] &lt;&lt; 8);
  result = result + ((file_buf[content + 3]));
  result = result &lt;&lt; 32;
  result = result + (file_buf[content + 4] &lt;&lt; 24);
  result = result + (file_buf[content + 5] &lt;&lt; 16);
  result = result + (file_buf[content + 6] &lt;&lt; 8);
  result = result + (file_buf[content + 7]);
  
  memcpy(&amp;resdouble, &amp;result, 8);
  wsprintf(Outbuf, L"HEX Result 8 Byte %16X", resdouble);
  OutputMessage(Outbuf, 0);
  swprintf(Outbuf, 200, L" Typ: REAL (8-byte): %Lf\n", resdouble);
  OutputMessage(Outbuf, 0);
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>HEX Result 8 Byte         937EE766
  Typ: REAL (8-byte): -1532001869,982873
  </code></pre>
  
  <p>Right result from page: 
  <a href="http://www.binaryconvert.com/result_double.html?hexadecimal=C1D6D420937EE766" rel="nofollow noreferrer">http://www.binaryconvert.com/result_double.html?hexadecimal=C1D6D420937EE766</a></p>
  
  <p>but would have to come out -1,532002893982.
  The comma is calculated incorrectly.</p>
  
  <p>Why do I get out the wrong double number and what do I have to do to get the result -1,532001 and not -1532001869,982873 ?</p>
  
  <p>EDIT:
  I try this from @ Gerhardh</p>
  
  <pre><code>(double)(*&amp;file_buf[content]);
  resdouble = *(double*)&amp;file_buf[content];
  swprintf(Outbuf, 200, L"Typ: REAL:\t%f\n", resdouble);
  OutputMessage(Outbuf, 0);
  swprintf(Outbuf, 200, L" Typ: HEX (8-byte): %X\n", resdouble);
  OutputMessage(Outbuf, 0);
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Typ: REAL:  5111310630843501598.......... 
  Datentyp: HEX (8-byte): 20D4D6C1
  </code></pre>
  
  <p>with byteswap in the first line</p>
  
  <pre><code>_byteswap_uint64(file_buf[content]);
  </code></pre>
  
  <p>i have the same result.</p>