title: set some consecutive bits in a byte
body: <p>I need an efficient method with the following signature:</p>
  
  <pre><code>public byte SetBits(byte oldValue, byte newValue, int startBit, int bitCount)
  </code></pre>
  
  <p>Which returns <code>oldValue</code>, only that starting from its <code>startbit</code> bit up to its <code>startbit + bitcount</code> bit (zero-based), it's replaced with the first <code>bitcount</code> bits of <code>newValue</code></p>
  
  <p>For example, if:</p>
  
  <ul>
  <li><code>oldValue = 11101101</code></li>
  <li><code>newValue = 10000011</code></li>
  <li><code>startBit = 1</code></li>
  <li><code>bitCount = 2</code></li>
  </ul>
  
  <p>Then the result would be: <code>11101111</code> (the segment <code>10</code> in <code>oldValue</code> is replaced with the corresponding <code>11</code> segment in <code>newValue</code>)</p>