CheckXorByte Function

Purpose

Computes the checksum for a range of bytes returning a byte value

Syntax

b = CheckXorByte(addr, count, [old])

b, old:8-bit integer
addr, count:iexp

Description

The function CheckXorByte() calculates a simple checksum (byte 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 8-bit values in the data.

Example

Local a$ = "This is a Test"

Print CheckXorByte(V:a$, Len(a$)) // 75

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

Mat Set a#() = 120

Mat Set b#() = -234

Dim cha_xor| = CheckXorByte(V:a#(0), ArraySize(a#()))

Dim ch_xor| = CheckXorByte(V:b#(0), ArraySize(b#()), cha_xor|)

Print cha_xor|, ch_xor| // 30, 243

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}