title: Understanding the bitwise AND Operator
body: <p>I have been reading about bit operators in Objective-C in Kochan's book, "Programming in Objective-C".</p>
  
  <p>I am VERY confused about this part, although I have really understood most everything else presented to me thus far.</p>
  
  <p>Here is a quote from the book:</p>
  
  <p><strong>The Bitwise AND Operator</strong></p>
  
  <p>Bitwise ANDing is frequently used for masking operations.  That is, this operator can be used easily to set specific bits of a data item to 0.  For example, the statement</p>
  
  <pre><code>w3 = w1 &amp; 3;
  </code></pre>
  
  <p>assigns to w3 the value of w1 bitwise ANDed with the constant 3.  This has the same ffect of setting all the bits in w, other than the rightmost two bits to 0 and preserving the rightmost two bits from w1.</p>
  
  <p>As with all binary arithmetic operators in C, the binary bit operators can also be used as assignment operators by adding an equal sign.  The statement</p>
  
  <pre><code>word &amp;= 15;
  </code></pre>
  
  <p>therefore performs the same function as the following:</p>
  
  <pre><code>word = word &amp; 15;
  </code></pre>
  
  <p>Additionally, it has the effect of setting all but the rightmost four bits of word to 0.  When using constants in performing bitwise operations, it is usually more convenient to express the constants in either octal or hexadecimal notation.</p>
  
  <p>OK, so that is what I'm trying to understand.  Now, I'm extremely confused with pretty much this entire concept and I am just looking for a little clarification if anyone is willing to help me out on that.</p>
  
  <p>When the book references "setting all the bits" now, all of the bits.. What exactly is a bit.  Isn't that just a 0 or 1 in 2nd base, in other words, binary?</p>
  
  <p>If so, why, in the first example, are all of the bits except the "rightmost 2" to 0?  Is it 2 because it's 3 - 1, taking 3 from our constant?</p>
  
  <p>Thanks!</p>