title: How to calculate crc for byte array?
body: <p>I understand how CRC for a byte can be calculated by modulo 2 division with a polynomial but I don't understand how do you calculate CRC for data consisting of byte arrays. CRC for a single byte can be calculated by this following code</p>
  
  <pre><code>#define WIDTH  8
  #define TOPBIT 1 &lt;&lt; 7
  #define POLYNOMIAL 0xD8
  
  uint8_t(uint8_t const message)
  {
      uint8_t remainder = 0;  
      remainder ^= message;
      for (uint8_t bit = 8; bit &gt; 0; --bit)
      {
          if (remainder &amp; TOPBIT)
          {
              remainder = (remainder &lt;&lt; 1) ^ POLYNOMIAL;
          }
          else
          {
              remainder = (remainder &lt;&lt; 1);
          }
      }
      return (remainder);
  
  }
  </code></pre>
  
  <p>but what about byte array ? I found above code on <a href="https://barrgroup.com/Embedded-Systems/How-To/CRC-Calculation-C-Code" rel="nofollow noreferrer">this site</a>, Author also gave the code for byte array where he just XOR'ed current remainder with next byte</p>
  
  <pre><code>remainder ^= (message[byte] &lt;&lt; (WIDTH - 8));
  </code></pre>
  
  <p>I don't quite understand why? why he XOR'ed to get in the next byte into remainder?</p>