title: How to check if a particular bit is set in C#
body: <p>In C#, I have a 32 bit value which I am storing in an int. I need to see if a particular bit is set. The bit I need is <code>0x00010000</code>.</p>
  
  <p>I came up with this solution:</p>
  
  <p>Here is what I am looking for:</p>
  
  <pre>
  Hex:       0    0    0    1     0    0    0    0    0 
  Binary   0000|0000|0000|0001|0000|0000|0000|0000|0000
  </pre>
  
  <p>So I right bit shift 16, which would give me:</p>
  
  <pre>
  Hex:       0    0    0    0     0    0    0    0    1
  Binary   0000|0000|0000|0000|0000|0000|0000|0000|0001
  </pre>
  
  <p>I then bit shift left 3, which would give me:</p>
  
  <pre>
  Hex:       0    0    0    0     0    0    0    0   8 
  Binary   0000|0000|0000|0000|0000|0000|0000|0000|1000
  </pre>
  
  <p>I then case my 32 bit value to a byte, and see if it equals 8. </p>
  
  <p>So my code would be something like this:</p>
  
  <pre><code>int value = 0x102F1032;
  value = value &gt;&gt; 16;
  byte bits = (byte)value &lt;&lt; 3;
  bits == 8 ? true : false;
  </code></pre>
  
  <p>Is there a simpler way to check if a particular bit is set without all the shifting?</p>