Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for a snapshot of the develop branch, built from commit c5994560ca.

Function template crc

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] 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.



The address where the memory block begins.


The number of bytes in the memory block.

Template Parameters:


The order of the modulo-2 polynomial divisor. (Width from the RMCA)


The (XOR) bit-mask to be applied to the output remainder, after possible reflection but before returning. (XorOut from the RMCA)


The (unaugmented) initial state of the polynomial remainder. (Init from the RMCA)


If True, input bytes are read lowest-order bit first, otherwise highest-order bit first. (RefIn from the RMCA)


If True, the output remainder is reflected before the XOR-mask. (RefOut from the RMCA)


The lowest coefficients of the divisor polynomial. The highest-order coefficient is omitted and always assumed to be 1. (Poly from the RMCA)


0 < Bits <= std::numeric_limits<uintmax_t>::digits


The checksum, which is the last (interim) remainder plus any output processing.