What is the most performant/correct way of doing a bit shift & mask?
<p>I've seen two different ways to approach combining bit shifting and masking, and was wondering if they were equivalent assuming the result is used as a boolean or if one had less issues or better performance than the other.</p>

<p>The two:</p>

<p><code>flags &amp; (BIT_MASK &lt;&lt; BIT_NUMBER)</code></p>

<p>or</p>

<p><code>(flags &gt;&gt; BIT_NUMBER) &amp; BIT_MASK</code></p>

<p>The former seems like it might have issues on some platforms depending on the size of <code>flags</code>, i.e. the bit shift might push the mask out the top of the temporary variable.  Is this an issue?  Are there any performance differences in up-shifting versus down-shifting?</p>

<p>Combining <code>BIT_MASK</code> and <code>BIT_NUMBER</code> into a single unambiguous mask strikes me as better again, but I'm working with legacy code that I want to minimize changes to.</p>
