十六进制数相加校验和计算程序
{-------------------------------------------------------------------------------
过程名: 16进制数相加效验和程序
作者: 陈新光
日期: 2008.07.24
参数: AStr: string; AIndex: Integer(从第几个字符开始计算)
返回值: string
-------------------------------------------------------------------------------}
function GetCheckStr(AStr: string; AIndex: Integer): string;
var
newstr1,he,oldstr:string;
tj:boolean;
i:integer;
begin
i:=1;
he:='';
tj:=true;
oldstr:=copy(AStr,AIndex,length(AStr)-AIndex+1);
while tj=true do
begin
newstr1:=copy(oldstr,i,2);
oldstr:=copy(oldstr,i+2,length(oldstr)-2);
//开始计算校验和并给he变量
if he='' then
begin
he:=inttohex(strtointdef('$'+newstr1,16)+ strtointdef('$'+'00',16),2);
he:=rightstr(he,2);
end
else
begin
he:=inttohex(strtointdef('$'+newstr1,16)+ strtointdef('$'+he,16),2);
he:=rightstr(he,2);
end;
if length(oldstr) =0 then tj:=false;
end;
Result:= AStr+he;
end;
过程名: 16进制数相加效验和程序
作者: 陈新光
日期: 2008.07.24
参数: AStr: string; AIndex: Integer(从第几个字符开始计算)
返回值: string
-------------------------------------------------------------------------------}
function GetCheckStr(AStr: string; AIndex: Integer): string;
var
newstr1,he,oldstr:string;
tj:boolean;
i:integer;
begin
i:=1;
he:='';
tj:=true;
oldstr:=copy(AStr,AIndex,length(AStr)-AIndex+1);
while tj=true do
begin
newstr1:=copy(oldstr,i,2);
oldstr:=copy(oldstr,i+2,length(oldstr)-2);
//开始计算校验和并给he变量
if he='' then
begin
he:=inttohex(strtointdef('$'+newstr1,16)+ strtointdef('$'+'00',16),2);
he:=rightstr(he,2);
end
else
begin
he:=inttohex(strtointdef('$'+newstr1,16)+ strtointdef('$'+he,16),2);
he:=rightstr(he,2);
end;
if length(oldstr) =0 then tj:=false;
end;
Result:= AStr+he;
end;
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/archive/2008/07/24/2940846.html