title: Using a bitmask in C#
body: <p>Let's say I have the following</p>
  
  <pre><code>int susan = 2; //0010
  int bob = 4; //0100
  int karen = 8; //1000
  </code></pre>
  
  <p>and I pass 10 (8 + 2) as a parameter to a method and I want to decode this to mean susan and karen</p>
  
  <p>I know that 10 is 1010</p>
  
  <p>but how can I do some logic to see if a specific bit is checked as in</p>
  
  <pre><code>if (condition_for_karen) // How to quickly check whether effective karen bit is 1
  </code></pre>
  
  <p>Right now all i can think of is to check whether the number i passed is </p>
  
  <pre><code>14 // 1110
  12 // 1100
  10 // 1010
  8 //  1000
  </code></pre>
  
  <p>When I have a larger number of actual bits in my real world scenario, this seems impractical, what is a better way using a mask to just check whether or not I meet the condition for just karen?</p>
  
  <p>I can think of shifting left then back then shifting right then back to clear bits other than the one I'm interested in, but this also seems overly complex.</p>