title: 64-bit floating point date and time Value to DateTime C#
body: <p>I have got a 64-bit floating point value that I need to convert to DateTime. What I have got is a C/Cpp block of code that does that but I can not understand it, so that I can do the same in C#, help should be appreciated.</p>
  
  <p>I do have this piece of information:</p>
  
  <blockquote>
    <p>Date and time of day is an eight byte, 64-bit floating-point value,
    representing the number of days since 1 January 1900. The time of day
    is represented as a fraction of a day.</p>
  </blockquote>
  
  <p>This is the C code:</p>
  
  <pre><code>//Time is first 8 bytes, converted to an 8-byte float, in units of days
  m1 = (unsigned int)(((((((((unsigned int)line[1]) &amp; 0xFF)&lt;&lt;8) | ((unsigned int)line[2])&amp;0xFF) &lt;&lt; 8) | ((unsigned int)line[3])&amp;0xFF) &lt;&lt; 8) | ((unsigned int)line[4])&amp;0xFF);
  m2 = (unsigned int)(((((((((unsigned int)line[5]) &amp; 0xFF)&lt;&lt;8) | ((unsigned int)line[6])&amp;0xFF) &lt;&lt; 8) | ((unsigned int)line[7])&amp;0xFF) &lt;&lt; 8) | ((unsigned int)line[8])&amp;0xFF);
  //Mask off mantissa bits and add back in the "hidden bit"
  time = (double)((m1 &amp; 0x000FFFFF) | 0x00100000) + ((double)m2)/thirty_two_bits;
  time = time / 32.0; //Normalise by "shifting right" to complete mantissa extraction
  exp = (m1 &gt;&gt; 20) - 0x0400 - 14; //The above calculation is good for an exponent of 14...
  while (exp != 0){
  if (exp &lt; 0){
      time = time / 2.0;
      exp++;
  }else{
      time = time * 2.0;
  exp--;
  }
  }
  time = time * 3600.0 * 24.0;    //Convert days to seconds
  </code></pre>
  
  <p>Where <code>line</code> is a byte array containing the 8-bytes for the date and time starting at index [1].</p>
  
  <p>A sample value for <code>line</code> is: <code>{X, 64, 228, 8, 46, 222, 232, 221, 125, ...}</code>.</p>
  
  <p>I did try the following but no correct results: (C#):</p>
  
  <pre><code>long longvalue = BitConverter.ToInt64(line, 1);
  DateTime dtm = DateTime.FromBinary(longvalue);
  </code></pre>