From: pandeng@telepath.com (Steve Schafer (TeamB)) Subject: Re: How to calculate CRC32 ? Date: 17 Jan 1999 00:00:00 GMT Message-ID: <36cd2eef.113961561@90.0.0.40> Content-Transfer-Encoding: 7bit References: <36A08984.F69CE0C9@compuserve.com> <36A0F5F2.52AB70B1@access.ch> <36A0F963.EC5D419C@earthlink.net> <36A10036.CFC3262@compuserve.com> Content-Type: text/plain; charset=us-ascii Organization: TeamB Mime-Version: 1.0 Reply-To: pandeng@telepath.com Newsgroups: borland.public.delphi.winapi On Sat, 16 Jan 1999 21:10:14 +0000, Sam King wrote: >Sample crc32 code in delphi for use on a data file would be apppreciated Here's a unit that implements a 32-bit CRC, using the same polynomial as the one used by PKZIP: unit uCrc; interface function GetStringCrc(const Data: String): LongInt; implementation var CrcTable: array[0..255] of LongInt; procedure InitTable; var I, J: Integer; begin for I := 0 to 255 do begin CrcTable[I] := I; for J := 0 to 7 do if Odd(CrcTable[I]) then CrcTable[I] := (CrcTable[I] shr 1) xor $EDB88320 else CrcTable[I] := CrcTable[I] shr 1; end; end; function GetStringCrc(const Data: String): LongInt; var I, Index: Integer; begin Result := -1; for I := 1 to Length(Data) do begin Index := (Ord(Data[I]) xor Result) and $000000FF; Result := (Result shr 8) xor CrcTable[Index]; end; Result := not Result; GetStringCrc := Result; end; initialization InitTable; end. -Steve