title: Fletcher checksum: Is a modulo-255 sum really the same as a one's complement sum
body: <p><strong>Short background to my question:</strong>
  I'm working on a small hobby project with a microcontroller communicating with a PC over UART. Right now I'm using COBS byte stuffing with 0x00 packet delimiter bytes and a simple 1-byte checksum that is either a two's complement running sum or a one's complement sum. My one's complement checksum implementation is very similar to <a href="https://www.rfc-editor.org/rfc/rfc1071" rel="nofollow noreferrer">Internet checksum</a> (page 7. The interesting part is seen below)</p>
  <pre><code>//  Fold 32-bit sum to 16 bits //
  while (sum&gt;&gt;16)
      sum = (sum &amp; 0xffff) + (sum &gt;&gt; 16);
  
  checksum = ~sum; 
  </code></pre>
  <p>A few days ago I found out about the Fletcher checksum:<br/>
  <a href="http://ieeexplore.ieee.org/document/1095369/" rel="nofollow noreferrer">Fletcher article</a><br/>
  <a href="https://dl.acm.org/citation.cfm?doid=53644.53648" rel="nofollow noreferrer">Fletcher implementation</a><br/>
  <a href="https://en.wikipedia.org/wiki/Fletcher%27s_checksum" rel="nofollow noreferrer">Fletcher Wikipedia</a></p>
  <p>Short code snippet from the Fletcher Wiki page:</p>
  <pre><code>for( index = 0; index &lt; count; ++index )
  {
      sum1 = (sum1 + data[index]) % 255;
      sum2 = (sum2 + sum1) % 255;
  }
  
  return (sum2 &lt;&lt; 8) | sum1;
  </code></pre>
  <p><strong>My question:</strong> In both articles above they say that Fletcher uses &quot;one's complement [mod(255)] checksums&quot; as though a mod-255 and one's complement sum are the same. Is that really true?</p>
  <ol>
  <li>It makes sense to me that the carry bits that makes one's complement checksums superior, could work in pretty much the same way in a mod-255 sum compared to the one's complement adder above. But with a mod-255 sum you can never get the value 0xFF (-0), only 0x00 (+0)?</li>
  <li>I guess that the mod-operator is slower (although it's linear so you can wait with the mod- calculation until the end of the sum).</li>
  <li>A nice feature (when using COBS) is that mod-255 will never produce 0x00 check bytes since the mod-255 sum can never be 0xFF (although that's easily fixed even in the one's complement adder above).</li>
  </ol>
  <p>Thank you so much for your time!</p>
  <p>Kind regards
  / Henrik</p>