Home > Back-end >  Delphi xor check the problem
Delphi xor check the problem

Time:09-20

Check us, some to want to add to 80, some don't have to add, I don't know what's the problem? Is there a understand teacher to instruct me?
The function StrToHexStr (const S: string) : string;
Var
I: Integer;
The begin
For I:=1 to Length (S) do
The begin
If I=1 then
Result:='+ IntToHex (word [1] (S), 2) +'
Else the Result: the Result +="' + IntToHex (word [I] (S), 2);
end;
end;

The function HexStrToStr (const S: string) : string;
Var
T: Integer;
Ts: the string;
M, Code: Integer;

The begin
T:=1;
Result:=';
While t<=Length (S) do
The begin
While not (S [t] in [' 0 '... '9', 'A'. The 'F', 'A'. The 'F']) do
Inc (t);
If (t + 1 & gt; Length (S)) or (not (S (t + 1] in [' 0 '... '9', 'A'. The 'F', 'A'. The 'F'])) then
Ts:='$' + S [t]
The else
Ts:='$' [t] + S + S (t + 1),
Val (ts, M Code);
If Code=0 then
Result: the Result=+ CRH (M);
Inc (t, 2);
end;
end;

The function HexToInt (STR: string) : word;
Var
I, the value: word;
Pos: word;
The begin
Value:=0;
Pos:=length (STR);
For I:=1 to pos do
The begin
Case STR [I] of
'f', 'f' :
Value:=value * 16 + 15;
'e', 'e' :
Value:=value * 16 + 14;
'd', 'd' :
Value:=value * 16 + 13;
'c', 'c' :
Value:=value * 16 + 12;
'b', 'b' :
Value: * 16 + 11=value;
'a', 'a' :
Value: * 16 + 10=value;
'0'.. '9' :
Value: the value=* 16 + word (STR) [I] - word (' 0 ');
The else
Result:=value;
exit;
end;
Result:=value;
end;

end;

The function HexToInt2 (Str1: string) : longInt;
Var I: integer;
The begin
Result:=0;
For I:=1 to length (Str1) do
The begin
If (Str1 [I] & gt;='0') and (Str1 [I] <='9') then
Result: the Result *=16 + StrToInt (Str1 [I])
The else
The begin
If (Str1 [I] & gt;='A') and (Str1 [I] <) then='F'
Result: the result *=16 + word (Str1 [I]) - 55
The else
The begin
Result:=0;
exit;
end;
end;
end;
end;

The function GetCheckBcc (AStr: string) : byte;//and or calculation Check Xor (BCC)
Var
T, I, j: integer;
StrNo: string;
A1: Byte;
AChar: Char;
The begin
T:=0;
J:=(length (AStr) div 3);
If (length (AStr) mod 3) & gt; 0 then
J:=j + 1;
For I:=1 to j do
The begin
StrNo:=Copy (AStr, (I - 1) * 3 + 1, 2);//s + s [I] [I + 1);
StrNo:=HexStrToStr (strNo);//Hex -> Str
AChar:=strNo [1].

T:=t xor word (Byte (AChar));
end;
Result:=t and $7 f;
end;

  • Related