Brief Information about the May 99 CSIG Meeting

A Review of the C Users Journal, 6/99, on CRC Calculations

Author: Colin Mahoney

Welcome to the C++ Users Group for May 1999. This month we will discuss an article by Colin Mahoney and algorithms by Ross Williams. The following is an excerpt from Ross Williams' home page.

CRC: A Paper On CRCs

This CRC web was created because of the popularity of a paper on CRC algorithms written by Ross Williams and posted to some Internet newsgroups on 19 August 1993. This paper is available by FTP as a pure text file. It can also be browsed directly on the web:

Here is the title and abstract of the paper:

A Painless Guide to CRC Error Detection Algorithms

This document explains CRCs (Cyclic Redundancy Codes) and their table-driven implementations in full, precise detail. Much of the literature on CRCs, and in particular on their table-driven implementations, is a little obscure. This document is an attempt to provide a clear and simple no-nonsense explanation of CRCs and to absolutely nail down every detail of the operation of their high-speed implementations. In addition to this, this document presents a parameterized model CRC algorithm called the "Rocksoft^tm Model CRC Algorithm". The model algorithm can be parameterized to behave like most of the CRC implementations around, and so acts as a good reference for describing particular algorithms. A low-speed implementation of the model CRC algorithm is provided in the C programming language. Lastly there is a section giving two forms of high-speed table driven implementations, and providing a program that generates CRC lookup tables.

// Listing 2	    ( from C Users Journal, June 1999 )
// Author: Colin Mahoney (
//      /link setargv.obj  req'd for wildcard handling in Microsoft VC++ (b.arnold)
#include <iostream>
#include <fstream>
#include <iterator>

using namespace std;
#include "crc.h"

int main( int argc, char* argv[] )
    if( argc < 2 )
	cerr << "Usage: CRC16 file1 file2...\n";
	return 1;

    typedef cdm_crc::CRCGenerator<16, 0x8005, 0, 0, true> CRC16;
    CRC16 crc16;
    cout.setf( ios_base::hex, ios_base::basefield );
    cout.setf( ios_base::showbase );
    for( int i = 1; i < argc; i++ )
	ifstream infile( argv[i] );
	infile.unsetf( ios_base::skipws );
	if( !infile )
	    cerr << "Error: unable to open " << argv[i] << '\n';
	crc16.Process( istream_iterator<unsigned char>( infile ),
	istream_iterator<unsigned char>() );
	unsigned long ncrcVal = crc16.GetNormalCRC();
	ncrcVal >>= (cdm_crc::CRCMaxBits-crc16.GetWidth() );
	cout << "File: " << argv[i] << '\t' << 
	"CRC-16 checksum: " << ncrcVal << '\n';
    return 0;

"Random Access" questions start at 7:30 Tuesday night.


Source Code Files

For help, email me at b a r n o l d @ b l a s t . n e t
Back to C++ Main Page