title: What does "int &= 0xFF" in a checksum do?
body: <p>I implemented this checksum algorithm I found, and it works fine but I can't figure out what this "&amp;= 0xFF" line is actually doing.</p>
  
  <p>I looked up the bitwise &amp; operator, and wikipedia claims it's a logical AND of all the bits in A with B.  I also read that 0xFF is equivalent to 255 -- which should mean that all of the bits are 1.  If you take any number &amp; 0xFF, wouldn't that be the identity of the number?  So A &amp; 0xFF produces A, right?</p>
  
  <p>So then I thought, wait a minute, checksum in the code below is a 32 bit Int, but 0xFF is 8bit.  Does that mean that the result of checksum &amp;= 0xFF is that 24 bits end up as zeros and only the remaining 8 bits are kept?  In which case, checksum is truncated to 8 bits.  Is that what's going on here?</p>
  
  <pre><code>    private int CalculateChecksum(byte[] dataToCalculate)
      {
          int checksum = 0;
  
          for(int i = 0; i &lt; dataToCalculate.Length; i++)
          {
              checksum += dataToCalculate[i];
          }
  
          //What does this line actually do?
          checksum &amp;= 0xff;
  
          return checksum;
      }
  </code></pre>
  
  <p>Also, if the result is getting truncated to 8 bits, is that because 32 bits is pointless in a checksum? Is it possible to have a situation where a 32 bit checksum catches corrupt data when 8 bit checksum doesn't?</p>