title: How to do bitwise operation decently?
body: <p>I'm doing analysis on binary data. Suppose I have two uint8 data values:</p>
  
  <pre><code>a = uint8(0xAB);
  b = uint8(0xCD);
  </code></pre>
  
  <p>I want to take the lower two bits from <code>a</code>, and whole content from <code>b</code>, to make a 10 bit value. In C-style, it should be like:</p>
  
  <pre><code>(a[2:1] &lt;&lt; 8) | b
  </code></pre>
  
  <p>I tried <code>bitget</code>:</p>
  
  <pre><code>bitget(a,2:-1:1)
  </code></pre>
  
  <p>But this just gave me separate <code>[1, 1]</code> logical type values, which is not a scalar, and cannot be used in the <code>bitshift</code> operation later.</p>
  
  <p>My current solution is:</p>
  
  <ol>
  <li><p>Make <code>a|b</code> (<code>a</code> or <code>b</code>):</p>
  
  <p><code>temp1 = bitor(bitshift(uint16(a), 8), uint16(b));</code></p></li>
  <li><p>Left shift six bits to get rid of the higher six bits from <code>a</code>:</p>
  
  <p><code>temp2 = bitshift(temp1, 6);</code></p></li>
  <li><p>Right shift six bits to get rid of lower zeros from the previous result:</p>
  
  <p><code>temp3 = bitshift(temp2, -6);</code></p></li>
  </ol>
  
  <p>Putting all these on one line:</p>
  
  <pre><code>result = bitshift(bitshift(bitor(bitshift(uint16(a), 8), uint16(b)), 6), -6);
  </code></pre>
  
  <p>This is doesn't seem efficient, right? I only want to get <code>(a[2:1] &lt;&lt; 8) | b</code>, and it takes a long expression to get the value.</p>
  
  <p>Please let me know if there's well-known solution for this problem.</p>