//-----------------------------------------------
//16进制字符转整数,16进制字符与字符串转换中间函数
//-----------------------------------------------
function HexToInt(hex: string): integer;
var
i: integer;
function Ncf(num, f: integer): integer;
var
i: integer;
begin
Result := 1;
if f = 0 then exit;
for i := 1 to f do
result := result * num;
end;
function HexCharToInt(HexToken: char): integer;
begin
if HexToken > #97 then
HexToken := Chr(Ord(HexToken) - 32);
Result := 0;
if (HexToken > #47) and (HexToken < #58) then { chars 0....9 }
Result := Ord(HexToken) - 48
else if (HexToken > #64) and (HexToken < #71) then { chars A....F }
Result := Ord(HexToken) - 65 + 10;
end;
begin
result := 0;
hex := ansiuppercase(trim(hex));
if hex = '' then
exit;
for i := 1 to length(hex) do
result := result + HexCharToInt(hex[i]) * ncf(16, length(hex) - i);
end;
//-----------------------------------------------
//字符串转16进制字符
//-----------------------------------------------
function StringToHex(str: string): string;
var
i : integer;
s : string;
begin
for i:=1 to length(str) do begin
s := s + InttoHex(Integer(str[i]),2);
end;
Result:=s;
end;
//-----------------------------------------------
//16进制字符转字符串
//-----------------------------------------------
function hextostring(str: string): string;
var
s,t:string;
i,j:integer;
p:pchar;
begin
s:='';
i:=1;
while i< length(str) do begin
t:=str[i]+str[i+1];
s:=s+chr(hextoint(t));
i:=i+2;
end;
result:=s;
end;