function HexString(s: string): string;
function HexChar(c: Char): Byte;
begin
case c of
'0'..'9': Result := Byte(c) - Byte('0');
'a'..'f': Result := (Byte(c) - Byte('a')) + 10;
'A'..'F': Result := (Byte(c) - Byte('A')) + 10;
else
Result := 0;
end;
end;
var
i,n: Integer;
src, dest: PChar;
begin
n := Length(s) div 2;
Result := StringOfChar(#0,n);
if n>0 then
begin
dest := @Result[1]; //dest := PChar(Result);
src := PChar(s);
for i := 0 to n-1 do
dest[i] := Char((HexChar(src[i*2]) shl 4) + HexChar(src[i*2+1]));
end;
end;