title: Most efficient way to set n consecutive bits to 1?
body: <p>I want to get a function that will set the <code>n</code> last bits of a numerical type to <code>1</code>. For example:</p>
  
  <pre><code>bitmask (5) = 0b11111 = 31
  bitmask (0) = 0
  </code></pre>
  
  <p>I, first, had this implementation (<code>mask_t</code> is just a <code>typedef</code> around <code>uint64_t</code>):</p>
  
  <pre><code>mask_t bitmask (unsigned short n) {
    return ((((mask_t) 1) &lt;&lt; n) - 1;
  }
  </code></pre>
  
  <p>Everything is fine except when the function hit <code>bitmask (64)</code> (the size of <code>mask_t</code>), then I get <code>bitmask (64) = 0</code> in place of 64 bits set to <code>1</code>.</p>
  
  <p>So, I have two questions:</p>
  
  <ol>
  <li><p>Why do I have this behavior ? Pushing the <code>1</code> by 64 shifts on the left should clear the register and remain with <code>0</code>, then applying the <code>-1</code> should fill the register with <code>1</code>s...</p></li>
  <li><p>What is the proper way to achieve this function ?</p></li>
  </ol>