How to make a Checksum in clarion

Hello,

How to make a Checksum in clarion.
This is an XOR of all bytes.

Example:
The input in Hex: 02 00 27 01 7c 30 30 30 30 30 30 30 30 30 30 32
Result CheckSum 8 Xor : 6A

Regards Frits.

You can loop throgh the inputs and call BXOR against current checksum and next input.

Mike,

Thanks.
But can you give me an example.

Input: 02 00 27 01 7c 30 30 30 30 30 30 30 30 30 30 32
Result: 6A

Regards Frits.

LOOP X# = 1 to N
Result = BXOR(INPUT[1],Result)
END

You might have to play a bit.
See: http://clarion.help/doku.php?id=bxor_return_bitwise_exclusive_or_.htm

1 Like

Hi Sean

remember to use val() around each character, so something like:

loop x = 1 to size(input)
  result = bxor(result,val(input[x]))
end

Thank you all,

My Result and it work.

St.Setvalue(Loc:String,st:clip)
St.SplitEvery(1)
MyResult = VAL(St.Getline(1))
Loop I# = 2 to St.Records() By 1
MyResult = BXOR(MyResult,VAL(St.Getline(I#)))
End
Message(MyResult)

I am a big fan of ST, but you’d get a much faster result just looping through the string instead of splitting everything to a queue first.

1 Like

In Clarion a STRING can be treated as an Array [ ] DIM(SIZE()) of STRING(1) so no need to SplitEvery. Implicit variables should be avoided.

X LONG

MyResult = VAL(Loc:String[1])
Loop x = 2 to LEN(CLIP(Loc:String)) By 1
   MyResult = BXOR(MyResult,VAL(Loc:String[x]))
End
Message(MyResult)