I am trying to convert a C code to Delphi/pascal, but somehow I cannot get it to work, my approach was like this :
function CheckLRC(s : PChar) : Char;
var
sum : char;
begin
sum := #0;
while (^s <> #0) do
begin
sum := (sum XOR ^s);
inc (s)
end;
result := sum;
end;
Original C code was :
Set LRC = 0
For each byte b in the buffer
do
Set LRC = (LRC + b) AND 0xFF
end do
Set LRC = (((LRC XOR 0xFF) + 1) AND 0xFF)
Hope anyone out there is able to help me, and can confirm this is the correct way to do an LRC checksum ?
I guess the exact equivalence of this function may be:
All “and $FF” in original code is unneeded here, since we are using a
byteas result.