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

Function crc16_ccitt

app/src/IO/Checksum.cpp:220–234  ·  view source on GitHub ↗

* @brief Computes a 16-bit CRC (CRC-CCITT) using polynomial 0x1021 and initial value 0x0000. */

Source from the content-addressed store, hash-verified

218 * @brief Computes a 16-bit CRC (CRC-CCITT) using polynomial 0x1021 and initial value 0x0000.
219 */
220static constexpr uint16_t crc16_ccitt(const char* data, const int length) noexcept
221{
222 uint16_t crc = 0x0000;
223
224 for (int i = 0; i < length; ++i) {
225 crc ^= static_cast<uint8_t>(data[i]) << 8;
226 for (int j = 0; j < 8; ++j)
227 if (crc & 0x8000)
228 crc = (crc << 1) ^ 0x1021;
229 else
230 crc <<= 1;
231 }
232
233 return crc;
234}
235
236//--------------------------------------------------------------------------------------------------
237// Checksum byte-packing helpers

Callers 1

Checksum.cppFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected