CheckXorLong Function

Purpose

Computes the checksum for a range of bytes returning a 32-bit value.

Syntax

l = CheckXorLong(addr, count, [old])

l, addr, count, old:iexp

Description

The function CheckXorLong() calculates a simple checksum (Long 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.

The checksum is a simple XOR-ing of 32-bit values (4 bytes) in the data.

Example

Local a$ = "This is a Test"

Print CheckXorLong(V:a$, Len(a$)) // 911103334

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

Mat Set a#() = 120

Mat Set b#() = -234

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

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

Print cha_xor%, ch_xor% // 1079902208, -2144124928

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: 25/09/2014 by James Gaite}