delphi BCC校验

来源:互联网 发布:外国电视台直播软件 编辑:程序博客网 时间:2024/04/26 07:29
function  BCCCheck(Command: string): string;
var
  Sum: Integer;
  iWork, i, j: Integer;
  sFinal, sTemp: string;
begin
  try
    i := length(Command) div 2;
    Sum := 0;
    for j := 1 to i do
    begin
      iWork := StrToInt('$' + Command[2 * j - 1] + Command[2 * j]);
      Sum := Sum + iWork;
    end;
    sTemp := IntToHex(Sum, 2);
    if Length(sTemp) > 2 then
    begin
      sTemp := RightStr(sTemp, 2);
    end;
    sFinal := '';
    for i := 0 to Length(sTemp) - 1 do
    begin
      sFinal := sFinal + IntToHex( ord(sTemp[i + 1]), 2);
    end;
    Result := sFinal;
  except
      Result := '';
  end;
end;
原创粉丝点击