title: Bit manipulation with or mask
body: <p>Suppose I have a variable inst which holds an encoded MIPS instruction. I want to set the rt field to 0 without changing the other fields. The rt field is a 5-bit field indexed from 16-20. I first tried:</p>
  
  <pre><code>inst = inst &amp; ~(1 &lt;&lt; 16);
  </code></pre>
  
  <p>which sets the rt field to 0. Then I want to put the value of a new variable new_reg into the rt field. I tried:</p>
  
  <pre><code>inst = inst | (new_reg &lt;&lt; 16);
  </code></pre>
  
  <p>Could anyone confirm whether these two lines of code are correct?</p>