Fletcher-16 Checksum Calculator
What is Fletcher-16?
The Fletcher-16 checksum algorithm computes a 16-bit checksum designed for error detection. It uses two 8-bit sums calculated while iterating through the data bytes, offering better error detection than simple addition checksums while being computationally less intensive than CRCs.
This implementation uses modulo 255 for its calculations, a common variant specified in RFC 1146 and used in examples like the one on Wikipedia. Some implementations might use modulo 256.
Understanding Checksums
A checksum is like a digital fingerprint of your data. When you create or download a file, its checksum is a unique value calculated from its contents. If even a single bit in the file changes, the checksum will be completely different. This makes checksums perfect for:
- File Verification: Compare checksums to ensure a file hasn't been corrupted during download or transfer
- Data Integrity: Quickly detect if files have been modified or tampered with
How Fletcher-16 Works (Mod 255)
- Initialize two sums,
sum1
andsum2
, to zero. - For each byte in the input data:
- Add the byte value to
sum1
, taking the result modulo 255. - Add the new
sum1
value tosum2
, taking the result modulo 255.
- Add the byte value to
- The final 16-bit checksum is formed by concatenating
sum2
(most significant byte) andsum1
(least significant byte). Result = (sum2
<< 8) |sum1
.