title: Merge uint16_t and int16_t into int32_t for data transmission in C
body: <p>I am confronted with the problem, to transmit an index (uint16_t) and data (int16_t) in a int32_t type, but I had no success yet.</p>
  
  <p>What I tried is the following:</p>
  
  <pre><code>int32_t buf = (int16_t) data;
  buf |= ((int32_t idx)&lt;&lt;16);
  </code></pre>
  
  <p>But this works only for positive data because of the 2 complement, which adds a one at the MSB. How can I achieve this?</p>