The pw_checksum module provides functions for calculating checksums.


constexpr uint16_t kCcittCrc16DefaultInitialValue = 0xFFFF

The default initial value for the CRC16.

uint16_t CcittCrc16(span<const std::byte> data, uint16_t initial_value = kCcittCrc16DefaultInitialValue)

Calculates the CRC16 of the provided data using polynomial 0x1021, with a default initial value of 0xFFFF.

To incrementally calculate a CRC16, use the previous value as the initial value.

uint16_t crc = CcittCrc16(my_data);

crc  = CcittCrc16(more_data, crc);


constexpr uint32_t kCrc32InitialValue = 0xFFFFFFFF

The initial value for the CRC32.

uint32_t Crc32(span<const std::byte> data)

Calculates the initial / one-time CRC32 of the provided data using polynomial 0x4C11DB7, with an initial value of 0xFFFFFFFF.

uint32_t crc = Crc32(my_data);
uint32_t Crc32(span<const std::byte> data, uint32_t previous_result)

Incrementally append calculation of a CRC32, need to pass in the previous result.

uint32_t crc = Crc32(my_data);
crc = Crc32(more_data, crc);


  • C

  • C++17


  • pw_span