Fletcher-16 Checksum

Medium C Validation Asked at Honeywell
Solve this problem

Implement the Fletcher-16 checksum, which catches byte-reordering errors that a plain additive sum would miss.

Constraints

  • Signature: `uint16_t fletcher16(const uint8_t *data, size_t len)`.
  • Both running sums are reduced modulo 255.
  • Return value is (sum2 << 8) | sum1.
  • Must not overflow an 8-bit accumulator.
  • An empty buffer returns 0.
Starter codeC
1#include <stdint.h>2#include <stddef.h>3 4uint16_t fletcher16(const uint8_t *data, size_t len) {5    // TODO6    return 0;7}