...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::crc — Compute the (unaugmented) CRC of a memory block.
// In header: <boost/crc.hpp> template<std::size_t Bits, typename ::boost::uint_t< Bits >::fast TruncPoly, typename ::boost::uint_t< Bits >::fast InitRem, typename ::boost::uint_t< Bits >::fast FinalXor, bool ReflectIn, bool ReflectRem> uint_t< Bits >::fast crc(void const * buffer, std::size_t byte_count);
Computes the polynomial remainder of a CRC run, assuming that buffer and byte_count describe a memory block representing the polynomial dividend. The division steps are altered so the result directly gives a checksum, without need to augment the memory block with scratch-space bytes. The first byte is considered the highest order, going down for subsequent bytes.
Note | |
---|---|
Unaugmented-style CRC runs perform modulo-2 polynomial division in an altered order. The trailing Bits number of zero-valued bits needed to extracted an (unprocessed) checksum is virtually moved to near the beginning of the message. This is OK since the XOR operation is commutative and associative. It also means that you can get a checksum anytime. Since data is being read byte-wise, a table of pre-computed remainder changes (as XOR masks) can be used to speed computation. |
Parameters: |
|
||||||||||||
Template Parameters: |
|
||||||||||||
Requires: |
0 < Bits <= |
||||||||||||
Returns: |
The checksum, which is the last (interim) remainder plus any output processing. |