title: Checking if a particular bit is set
body: <p>I'm trying to check if the 2nd bit from LSB is set.
  I use the below function to do this.
  If it was the 1st bit I could simple return <code>(uintptr_t) p &amp; 1</code>.
  Since I'm checking if the second bit is set, I'm doing one more operation <code>==</code>.
  Is there a clever way with which this can be achieved using just one instruction?</p>
  
  <pre><code>static inline bool is2ndBitSet(void* p)
  {
      return ((uintptr_t) p &amp; 2) == 2;
  }
  </code></pre>
  
  <p><strong>EDIT:</strong>
  I just tried the suggestions in the comments and yes, I'm doing redundant comparison</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdint.h&gt;
  static inline bool is2ndBitSet(void* p)
  {
      return ((uintptr_t) p &amp; 2);
  }
  
  int main()
  {
      unsigned long* ptr = (unsigned long*) 0x4;
      unsigned long* ptr1 = (unsigned long*) 0x3;
      if(is2ndBitSet(ptr))
      {
          printf("bit is set\n");
      }
      else
      {
          printf("bit is not set\n");
      }
      if(is2ndBitSet(ptr1))
      {
          printf("bit is set\n");
      }
      else
      {
          printf("bit is not set\n");
      }
      return 0;
  }
  </code></pre>
  
  <p>output</p>
  
  <pre><code>bit is not set
  bit is set
  </code></pre>