title: Concatenate Bits from 3 characters, taken from different locations in the bitset
body: <p>I am trying to concatenate the bits of 3 characters <code>a</code>, <code>b</code> and <code>c</code> into a bitset of 16 bits. The constraints are the following:</p>
  <ul>
  <li>Concatenate the last 2 bits of <code>a</code> into <code>newVal1</code></li>
  <li>Concatenate the 8 bits of <code>b</code> into <code>newVal1</code></li>
  <li>Concatenate the first 2 bits of <code>c</code> into <code>newVal1</code></li>
  </ul>
  <p>On paper I am getting: <code>1111111111110000</code> same as the result. But I am not sure of the way I am concatenating the bits. First shift left by <code>14</code> character <code>a</code> then shift left by <code>6</code> character <code>b</code> and finally, since There is no space left for character <code>c</code> then shift right by <code>2</code>. <strong>Is there a better way to do it? It's already confusing for me</strong></p>
  <hr />
  <pre><code>#include &lt;iostream&gt;
  #include &lt;bitset&gt;
  
  int main() {
     int a = 0b11111111 &amp; 0b00000011;
     int b = 0b11111111;
     int c = 0b11111111 &amp; 0b11000000;
     
     uint16_t newVal1 = (a &lt;&lt; 14) + (b &lt;&lt; 6) + (c &gt;&gt; 2 );
     std::cout &lt;&lt; std::bitset&lt;16&gt;(newVal1).to_string() &lt;&lt; std::endl;
     
     return 0;
  }
  </code></pre>