MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / fletcher16

Function fletcher16

app/src/IO/Checksum.cpp:185–196  ·  view source on GitHub ↗

* @brief Computes a Fletcher-16 checksum. */

Source from the content-addressed store, hash-verified

183 * @brief Computes a Fletcher-16 checksum.
184 */
185static constexpr uint16_t fletcher16(const char* data, const int length) noexcept
186{
187 uint16_t sum1 = 0;
188 uint16_t sum2 = 0;
189
190 for (int i = 0; i < length; ++i) {
191 sum1 = (sum1 + static_cast<uint8_t>(data[i])) % 255;
192 sum2 = (sum2 + sum1) % 255;
193 }
194
195 return (sum2 << 8) | sum1;
196}
197
198/**
199 * @brief Computes a 16-bit CRC (CRC-16-MODBUS) using polynomial 0x8005 (reflected: 0xA001).

Callers 1

Checksum.cppFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected