Crc32 Function

Purpose

computes the Cyclic Redundancy Check checksum for a range of bytes returning a 32-bit value.

Syntax

w = Crc32(addr, count, [old])

w = Crc32(str, [old])

w, old, addr, count:iexp
str:string

Description

The function Crc32() calculates a cyclic redundancy checksum (32-bits value) for a block of data: count bytes from the address addr. The optional parameter old is to be used if you want to create a checksum for more than one block, old must contain the checksum for the other block.

Example

Local a$ = "Dies ist eine Test“"

Dim a#(10), b#(10)

Dim b% = 923454545

Mat Set a#() = 120

Mat Set b#() = -234

Dim cha_xor% = Crc32(V:a#(0), ArraySize(a#()))

Dim ch_xor% = Crc32(V:b#(0), ArraySize(b#()), cha_xor%)

Print Crc32(b%) // prints 2091025660

Print Crc32(a$) // 1965147545

Print cha_xor%  // 1254148786

Print ch_xor%   // 409962355

Remarks

The calculation of data with CheckXorByte, CheckXorShort, CheckXorLong (or CheckSumxxx()) is very fast (up to 10 times faster than Crc16() or Crc32()).

A checksum is a form of redundancy check, a simple way to protect the integrity of data by detecting errors in data that are sent through space (telecommunications) or time (storage). It works by adding up the basic components of the data, typically the asserted bits, and storing the resulting value. Anyone can later perform the same operation on the data, compare the result to the authentic checksum, and (assuming that the sums match) conclude that the data was probably not corrupted.

See Also

CheckSumByte(), CheckSumLong(), CheckSumShort(), CheckXorByte(), CheckXorLong(), CheckXorShort(), Crc16(), Crc32()

{Created by Sjouke Hamstra; Last updated: 27/09/2014 by James Gaite}