Where would I use a bitwise operator in JavaScript?
<p>I've read <strong><a href="http://stackoverflow.com/questions/276706/what-are-bitwise-operators">this</a></strong> (<a href="http://stackoverflow.com/questions/276706/what-are-bitwise-operators">http://stackoverflow.com/quest...</a>), so I know <strong>what</strong> bitwise operators 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">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>
