title: How does condition statement work with bit-wise operators?
body: <p>I tried to understand how if condition work with bitwise operators.
  A way to check if a number is even or odd can be done by:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  string test()
  {
      int i = 8;  //a number
      if(i &amp; 1)
        return "odd";
  
      else
        return "even";       
  }
  
  int main ()
  {
    cout &lt;&lt; test();
    return 0;
  }
  </code></pre>
  
  <p>The Part I don't understand is how the if condition work. In this case if i = 8 then the in If statement it is doing <code>1000 &amp; 1</code> which should gives back 1000 which equal 8.</p>
  
  <p>If i = 7, then in if statement it should be doing <code>111 &amp; 1</code> which gives back 111 which equal 7</p>
  
  <p>Why is it the case that if(8) will return "even" and if(7) return "odd"? I guess I want to understand what the if statement is checking to be True and what to be False when dealing with bit-wise operators.</p>
  
  <p>Just A thought when I wrote this question down is it because it's actually doing </p>
  
  <pre><code>for 8: 1000 &amp; 0001 which gives 0
  for 7: 0111 &amp; 0001 which gives 1?
  </code></pre>