title: Confusing type conversion - 2 Bytes to Double
body: <p>I was recently asked to take over a project in which waveform data is sampled from a power converter and sent to an intelligent agent where calculations are done and the appropriate actions are taken based on the results.  </p>
  
  <p>The following (java)snippet is what the previous coder used to convert the byte array into an array of doubles: </p>
  
  <pre><code>        LSB = (0XFF &amp; (int)ipPacket[index]);
          double temp = LSB/256.0;
  
          MSB = (byte)(0XFF &amp; (byte)ipPacket[index+1]);
          double output = (double)(MSB + temp);
  
          ConvCurrentPhaseR[doubleArrayIndex] = (double)(output);
  </code></pre>
  
  <p>(Note: LSB is an integer and MSB is a byte)</p>
  
  <p>I honestly have no idea how the previous coder came up with this conversion. It doesn't make any sense to me. Why divide LSB by 256? Even if the original data is a float (4 bytes) how are we getting a double (8 bytes) out of only 2 bytes? Could anyone possibly explain what is going on with this piece of code?</p>
  
  <p>Thanks in advance for any help provided!</p>