On Wednesday, July 9, 2003, at 11:02 AM, Victoria Ames wrote: [SNIP]
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 : [SNIP] Expected CRC-8 : EA Optimal CRC-8 : Û
Does anyone know why the 8 bit example does not seem to work?
I can't tell at this point. The problem could be that the results of the "crc_8" object is an "unsigned char". The built-in character types can take the same numeric operations as the bigger built-in integral types (i.e. "int"). However, the character types differ from the other integral types since the character types act as C++ text system types. So when an object of a built-in character type is printed, its text value is printed instead of its numeric value. The solution is to convert the result to a numeric-only integral type. Try std::cout << std::hex << static_cast<unsigned>( crc_8() ) << std::endl; to check the numeric value of the result. Then you can tell if the result is correct. If it's not, send us another message. With my hypothesis, the problem is only in the printing. You would have no problem in using the result for further mathematical analyses. Daryle