# CRC

This unit implements words that compute CRC checksum using the regularly used
polynomials.

The parameters used are CRC32-ANSI and CRC16-XMODEM. If you look at the code
you'll see that it's rather easy to craft other crc words with custom
parameters.

## Batch API

Each word in the API below is self-contained and directly yield the correct
result. Nothing special to add here.

crc16[]
crc32[] ( a u -- crc )
  Compute the checksum of range.

crc16
crc32 ( stream -- crc )
  Compute the checksum of specified [io/stream] from its current position until
  EOF.

crc16<<
crc32<< ( "path" -- crc )
  Compute the checksum of file at "path".

## Byte-by-byte API

The words below have to be used in a specific sequence. First, you initialize
your CRC with crc16$ or crc32$ then accumulate with crc, then finalize with
crcdone.

crc16$
crc32$ ( -- crc )
  Initialize the "crc" alias and yield the correct initial value for the chosen
  CRC algorithm.

acccrc ( crc c -- crc )
  Accumulate a single character into the crc checksum. This is an alias set by
  the initializer.

acccrc[] ( crc a u -- crc )
  Loop over range "a u" and apply "acccrc" to it.

crcdone ( crc -- crc )
  Finalize the crc by applying a "closing" operation on it.

## Private API

reflect ( poly -- n )
  Reverse polynomial "n" by swapping all bits by its center. If "poly" is less
  than 32 bit, you have to right-shift the result appropriately.

  For example, "$1021 reflect" yields $84080000.
