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

Function crc8

app/src/IO/Checksum.cpp:104–116  ·  view source on GitHub ↗

* @brief Computes an 8-bit CRC (CRC-8) using polynomial 0x31. */

Source from the content-addressed store, hash-verified

102 * @brief Computes an 8-bit CRC (CRC-8) using polynomial 0x31.
103 */
104static constexpr uint8_t crc8(const char* data, const int length) noexcept
105{
106 uint8_t crc = 0xFF;
107 for (int i = 0; i < length; ++i) {
108 crc ^= static_cast<uint8_t>(data[i]);
109 for (int j = 0; j < 8; ++j)
110 if (crc & 0x80)
111 crc = (crc << 1) ^ 0x31;
112 else
113 crc <<= 1;
114 }
115 return crc;
116}
117
118/**
119 * @brief Computes an additive modulo-256 checksum.

Callers 1

Checksum.cppFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected