使用16进制数进行相加并得出最后一位作为校验和的程序function getsum(s: string): string; var i: integer; sum: integer; begin sum := 0; for i := 1 to round(length(s) / 2) do begin sum := sum + strtoint('$' + copy(s, i * 2 - 1, 2)); end; result := inttohex((sum mod 256), 2); end;
var
i: integer;
sum: integer;
begin
sum := 0;
for i := 1 to round(length(s) / 2) do
begin
sum := sum + strtoint('$' + copy(s, i * 2 - 1, 2));
end;
result := inttohex((sum mod 256), 2);
end;
保存最后一个字节。转换为char
s:=getsum(str);
c:=chr(strtoint('$'+s));