#include #include // Generator polynomial GM(x) = x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1 const uint32_t generator = 0x04C11DB7; // Compute CRC32 over a buffer of data uint32_t compute_crc32(std::vector& data) { uint32_t crc = 0x00000001; // Initial remainder for(auto& byte : data) { crc ^= static_cast(byte) << 24; for (unsigned i = 0; i < 8; ++i) { if (crc & 0x80000000) { crc = (crc << 1) ^ generator; } else { crc <<= 1; } } } return crc; } int main() { // Test with some data std::vector data = { 214,121,0,98,98,0,3,191,0,7,0,0,0,0,0,0,0,0,0,0 }; uint32_t crc = compute_crc32(data); std::cout << "CRC32: " << std::dec << (int)crc << std::endl; uint8_t crcOctets[4]; crcOctets[0] = (crc >> 24) & 0xFF; crcOctets[1] = (crc >> 16) & 0xFF; crcOctets[2] = (crc >> 8) & 0xFF; crcOctets[3] = (crc >> 0) & 0xFF;/////////// // Print the CRC octets for (int i = 0; i < 4; i++) { std::cout <<"CRC Octet"<