title: What is the correct way to set bit in bitmask?
body: <p>I'm little bit confuced about a proper way to set bits in bitmask. I have the following function and flags:</p>
  
  <pre><code>var userBmask = 0;
  
  const EMAIL_CONFIRMED = 1;
  const EMAIL_UNSUBSCRIBED = 2; 
  
  setBit: function (bit) {
      userBmask |= 1 &lt;&lt; bit; // 10
  }
  </code></pre>
  
  <p>Let's say I want to set bit for email confirmation:</p>
  
  <pre><code>setBit(EMAIL_CONFIRMED);
  </code></pre>
  
  <p>After the line above my <code>userBmask</code> is: <code>10</code>. But I'm not sure this is correct because actualy I set second bit instead first. Should I rewrite <code>setBit</code> function to the folowing to set bits from most right bit?:</p>
  
  <pre><code>setBit: function (bit) {
      userBmask |= 1 &lt;&lt; bit - 1; // 01
  }
  </code></pre>
  
  <p>Now after <code>setBit(EMAIL_CONFIRMED)</code> I get result <code>01</code></p>
  
  <p><strong>EDIT:</strong>
  Thanks for your answers. Please look at the following. Becase I'm using javascript that is 32bit I can have bitmask with `0...31 bits. But if I try to set the last available bit (with is 31) I get negative number:</p>
  
  <pre><code>const NEXT_BIT = 31; 
  
  setBit(NEXT_BIT); // userBmask now is -10000000000000000000000000000000
  </code></pre>
  
  <p>Is it expected behavior and could be result of possible bugs?</p>