title: C++: how to cast 2 bytes in an array to an unsigned short
body: <p>I have been working on a legacy C++ application and am definitely outside of my comfort-zone (a good thing). I was wondering if anyone out there would be so kind as to give me a few pointers (pun intended).</p>
  
  <p>I need to cast 2 bytes in an unsigned char array to an unsigned short. The bytes are consecutive. </p>
  
  <p>For an example of what I am trying to do:</p>
  
  <p>I receive a string from a socket and place it in an unsigned char array. I can ignore the first byte and then the next 2 bytes should be converted to an unsigned char. This will be on windows only so there are no Big/Little Endian issues (that I am aware of).</p>
  
  <p>Here is what I have now (not working obviously):</p>
  
  <pre><code>//packetBuffer is an unsigned char array containing the string "123456789" for testing
  //I need to convert bytes 2 and 3 into the short, 2 being the most significant byte
  //so I would expect to get 515 (2*256 + 3) instead all the code I have tried gives me
  //either errors or 2 (only converting one byte
  unsigned short myShort;
  myShort = static_cast&lt;unsigned_short&gt;(packetBuffer[1])
  </code></pre>