PDA

View Full Version : Xor Sum



Sphere
- 6th December 2006, 22:39
I need to understand how to work out a checksum for this A0 00 00 04 20 00 AF, the answer is 2B but I dont understand how to work out an XOR sum. According to the website I got this from, its says 2B is an XOR sum of Bytes 1-7.

Sphere.....

keithdoxey
- 6th December 2006, 23:59
Just start with byte 1 and XOR each of the following bytes.
The sequence works like this...

A0
XOR 00 = A0
XOR 00 = A0
XOR 04 = A4
XOR 20 = 84
XOR 00 = 84
XOR AF = 2B

SteveB
- 7th December 2006, 00:06
I need to understand how to work out a checksum for this A0 00 00 04 20 00 AF, the answer is 2B but I dont understand how to work out an XOR sum. According to the website I got this from, its says 2B is an XOR sum of Bytes 1-7.

Sphere.....

Here is a simple demo of how to accomplish this in PBP:


DataPacket var byte[7]
XORsum var byte

DataPacket[0] = A0
DataPacket[1] = 00
DataPacket[2] = 00
DataPacket[3] = 04
DataPacket[4] = 20
DataPacket[5] = 00
DataPacket[6] = AF

XORsum = DataPacket[0] ^ DataPacket[1]
XORsum = XORsum ^ DataPacket[2]
XORsum = XORsum ^ DataPacket[3]
XORsum = XORsum ^ DataPacket[4]
XORsum = XORsum ^ DataPacket[5]
XORsum = XORsum ^ DataPacket[6]

HTH,
Steve

EDIT: Corrected the DataPacket array declaration to 7 bytes

Sphere
- 7th December 2006, 07:52
Thanks alot keithdoxey and SteveB it worked first time, it will save me alot of code space.

Thanks again Sphere.