title: Why does this return 42 instead of 682?
body: <p>Working with bits in C.  I am trying to create a function that looks for a specific string of bits in a larger bit string.  My thinking was to compare the two using the &amp; operator, then shifting the string left and repeating.  If the operator returns the larger number (because no bits should change), the pattern has been found.  Unfortunately, that seems to be a flawed method, since what I have narrowed down to is that when this happens it in fact returns the smaller string, throwing what I thought I knew into doubt.</p>
  
  <p>I suppose my guess is that the zeroes in front aren't in fact added when doing this operation, but i'm wary of rationalizing the wrong theory in my coding, so here I am.  Please explain, none of the resources I have found really address what is going on here.  Thanks in advance.</p>
  
  <pre><code>int main (void)
  {
      unsigned int x = 682;   //      1010101010
      unsigned int pattern = 42; //       101010
      unsigned int temp;
  
      temp = x &amp; pattern;
      printf("%i\n", temp);
  
      return 0;
  }
  
  </code></pre>