title: Algorithm to generate bit mask
body: <p>I was facing this unique problem of generating a bit-mask based on the input parameter. For example,</p>
  
  <p>if param = 2, then the mask will be 0x3  (11b)
  if param = 5, then the mask will be 0x1F (1 1111b)</p>
  
  <p>This I implemented using a for-loop in C, something like</p>
  
  <pre><code>int nMask = 0;
  for (int i = 0; i &lt; param; i ++) {
  
      nMask |= (1 &lt;&lt; i);
  }
  </code></pre>
  
  <p>I would like to know if there is a better algorithm ~~~</p>