The crc32 procedure

Description

The crc32 procedure computes a 32 bit Cyclic Redundancy Check (CRC).

Parameter

  1. The first parameter is a reference to a variable of integer type or word type which is used to accumulate the result.
  2. The second parameter is an expression of byte type or char type, and is the value to use as the data.
  3. The third parameter is an expression of integral type, and is the value to use as the CRC polynomial. If this parameter is not supplied then the default CRC polynomial (i.e. $04C11DB7) is used.

Example

   //****************************************************
   // This program uses the built-in procedure crc32
   //  to calculate the 32-bit CRC for a file.
   // Basically the program asks for the name of the file
   // and then it reads the file a character at a time
   // passing each byte to crc32.
   // Finally it calls crc32 4 times with zero to
   //  complete the crc calculation. This is part of
   //  the process of calculating CRCs.
   //****************************************************
   program filecrc(input, output);
   var
      fn : filename;
      f : file of char;
      c : char;
      crc : integer;
   begin
      write('Enter filename: ');
      readln(fn);
      writeln('Calculating CRC...');
      crc := 0;
      reset(f, fn);
      while not eof(f) do
         begin
            read(f, c);
            crc32(crc, c);
         end;

      crc32(crc, 0);
      crc32(crc, 0);
      crc32(crc, 0);
      crc32(crc, 0);

      writeln('CRC for ', fn, ' is ', crc, ' (', hex(crc), ')');
   end.

Portability

Operating Systems: All
Standard Pascal: No