CRC problem with 8 bit truncated polynomial
When I have tried examples using 16 or 32 bit truncated polynomials this library works perfectly. Example that works : unsigned char const data[] = { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39 }; std::size_t const data_len = sizeof( data ) / sizeof( data[0] ); std::cout << "Expected CRC-CCITT : 29B1" << std::endl; // Simulate CRC-CCITT with the optimal version boost::crc_optimal<16, 0x1021, 0xFFFF, 0, false, false> crc_ccitt2; crc_ccitt2 = std::for_each( data, data + data_len, crc_ccitt2 ); std::cout << "Optimal CRC-CCITT : " << std::hex << crc_ccitt2() << std::endl; However, when I have tried examples using 8 bit truncated polynomials I fail to get a meaningful checksum. Example that doesn't work : std::cout << "Expected CRC-8 : EA" << std::endl; boost::crc_optimal<8, 0x9B, 0, 0, false, false> crc_8; crc_8 = std::for_each( data, data + data_len, crc_8 ); std::cout << "Optimal CRC-8 : " << std::hex << crc_8() << std::endl; The results I get are : Expected CRC-CCITT : 29B1 Optimal CRC-CCITT : 29b1 Expected CRC-8 : EA Optimal CRC-8 : Û Does anyone know why the 8 bit example does not seem to work? Victoria
Hi Victoria,
Example that doesn't work : std::cout << "Expected CRC-8 : EA" << std::endl; boost::crc_optimal<8, 0x9B, 0, 0, false, false> crc_8; crc_8 = std::for_each( data, data + data_len, crc_8 ); std::cout << "Optimal CRC-8 : " << std::hex << crc_8() << std::endl;
I'm guessing this should be std::cout << "Optimal CRC-8 : " << std::hex << (unsigned)crc_8() << std::endl; The way iostreams format chars is most likely not what you wanted. HTH, Volodya
participants (2)
-
victoriaames
-
Vladimir Prus