title: C macro to set multiple bits
body: <p>I am working on a microcontroller in C. Part of this involves changes bit values in registers. I have come up with a few macros to make things easier:</p>
  
  <pre><code>#define BIT_SET(addr, shift) (addr | (1 &lt;&lt; shift))
  #define BIT_RESET(addr, shift) (addr &amp; ~(1 &lt;&lt; shift))
  #define BIT_GET(addr, shift) (addr &amp; (1 &lt;&lt; shift))
  ...
  reg1 = BIT_SET(reg1, 3); //set bit 3
  ...
  </code></pre>
  
  <p>However, now I want to make a macro which will change several bits at a time. For example, may want to change the first 3 bits of <code>10101010</code> to <code>110</code>, resulting in the number <code>11001010</code>.</p>
  
  <p>Can I do this in C? Or am I approaching this the wrong way?</p>