title: Where would I use a bitwise operator in JavaScript?
body: <p>I've read <a href="https://stackoverflow.com/questions/276706/what-are-bitwise-operators">'what are bitwise operators?'</a>, so I know <strong>what</strong> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators" rel="noreferrer">bitwise operators</a> are but I'm still not clear on how one might use them. Can anyone offer any real-world examples of where a bitwise operator would be useful in JavaScript?</p>
  
  <p>Thanks.</p>
  
  <h2>Edit:</h2>
  
  <p>Just digging into the <strong><a href="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" rel="noreferrer">jQuery source</a></strong> I've found a couple of places where bitwise operators are used, for example: (only the &amp; operator)</p>
  
  <pre><code>// Line 2756:
  event.which = (event.button &amp; 1 ? 1 : ( event.button &amp; 2 ? 3 : ( event.button &amp; 4 ? 2 : 0 ) ));
  
  // Line 2101
  var ret = a.compareDocumentPosition(b) &amp; 4 ? -1 : a === b ? 0 : 1;
  </code></pre>