Originally Posted by
DazC
Ok, so if I had an input figure of 3642 and another of 1532, what would the outcome be?
Infinity, or so it seems
Originally Posted by
DazC
I have a section of ladder logic running some XOR functions on 4 and 5 digit numbers and I'm trying to work out how it's doing the calculations.
The manual way of computing an XOR cksum would be to take each hex byte, convert it to binary & get the result of the XOR with the previous hex byte.
So taking the hex string [87 A5 03 00 40 00 A7 03 30 00 00 B0 01 10 B4 03 00 01 00 A4 02 00 01], we'd start with hex "87". Since there is no bit before it, according to the CSAFE protocol we would XOR with hex "00", which basically just gives you hex "87" as the result again.
hex 00 = binary 00000000
hex 87 = binary 10000111
An XOR takes each binary bit value in the 1st binary string and compares it to the corresponding binary bit value in the 2nd binary string. If the values match (1 and 1, or 0 and 0) then the XOR of the bits would be a 0. If the values don't match (ie. 1 and 0, or 0 and 1) then the XOR of the bits would be 1.
So in the values above, XOR of the two binary strings would be as follows:
(hex 00 bit) ^ (corresponding hex 87 bit)
0 ^ 1 = 1
0 ^ 0 = 0
0 ^ 0 = 0
0 ^ 0 = 0
0 ^ 0 = 0
0 ^ 1 = 1
0 ^ 1 = 1
0 ^ 1 = 1
So the final XOR of the hex byte 00 and hex byte 87 would be binary 10000111 (which is also hex 87).
Next, we'd move onto comparing the previous result (ie. binary 10000111) with the next hex byte "A5"
hex 87 = binary 10000111 hex A5 = binary 10100101
(hex 87 bit) ^ (corresponding hex A5 bit)
1 ^ 1 = 0
0 ^ 0 = 0
0 ^ 1 = 1
0 ^ 0 = 0
0 ^ 0 = 0
1 ^ 1 = 0
1 ^ 0 = 1
1 ^ 1 = 0
So the final XOR of hex byte 87 and hex byte A5 would be binary 00100010 (which is also hex 22).
Next, we'd move onto comparing the previous result (ie. binary 00100010) with the next hex byte "03"
hex 22 = binary 00100010 hex 03 = binary 00000011
(hex 22 bit) ^ (corresponding hex 03 bit)
0 ^ 0 = 0
0 ^ 0 = 0
1 ^ 0 = 1
0 ^ 0 = 0
0 ^ 0 = 0
0 ^ 0 = 0
1 ^ 1 = 0
0 ^ 1 = 1
So the final XOR of hex byte 22 and hex byte 03 would be binary 00100001 (which is also hex 21).
We'd continue calculating the summation of hex XORs in this manner until all of the hex bytes in the original hex string were processed. The end result would be the checksum and in the case of the CSAFE protocol, the resultant hex byte would be included as the last byte of the data sent in transmissions from the exercise bike to the host program. In the CSAFE protocol, the cksum value is important since the host program either sees a valid cksum and processes the data, or sees an invalid cksum and tosses out the request.
Shed any light? Do it manually

ETA: The above is from a quick google, I'm not
that good at this