Function template crc

| Home | Libraries | People | FAQ | More

## Function template crc

boost::crc — Compute the (unaugmented) CRC of a memory block.

## Synopsis

    // 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);

## Description

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:

`buffer` | The address where the memory block begins.
`byte_count` | The number of bytes in the memory block.

Template Parameters:

`Bits` | The order of the modulo-2 polynomial divisor. (Width from the RMCA)
`FinalXor` | The (XOR) bit-mask to be applied to the output remainder, after possible reflection but before returning. (XorOut from the RMCA)
`InitRem` | The (unaugmented) initial state of the polynomial remainder. (Init from the RMCA)
`ReflectIn` | If `True`, input bytes are read lowest-order bit first, otherwise highest-order bit first. (RefIn from the RMCA)
`ReflectRem` | If `True`, the output remainder is reflected before the XOR-mask. (RefOut from the RMCA)
`TruncPoly` | The lowest coefficients of the divisor polynomial. The highest-order coefficient is omitted and always assumed to be 1. (Poly from the RMCA)

Requires: | 0 < Bits <= `std::numeric_limits<uintmax_t>::digits`
Returns: | The checksum, which is the last (interim) remainder plus any output processing.