title: Signed extension from 24 bit to 32 bit in C++
body: <p>I have 3 unsigned bytes that are coming over the wire separately.</p>
  
  <pre><code>[byte1, byte2, byte3]
  </code></pre>
  
  <p>I need to convert these to a signed 32-bit value but I am not quite sure how to handle the sign of the negative values. </p>
  
  <p>I thought of copying the bytes to the upper 3 bytes in the int32 and then shifting everything to the right but I read this may have unexpected behavior.</p>
  
  <p>Is there an easier way to handle this? </p>
  
  <p>The representation is using two's complement.</p>