H
hangzhou492
Unregistered / Unconfirmed
GUEST, unregistred user!
代码:
function StrToHex(AStr: string): string;
var
I : Integer;
//Tmp: string;
begin
Result := '';
For I := 1 to Length(AStr)do
begin
Result := Result + Format('%2x', [Byte(AStr[I])]);
end;
I := Pos(' ', Result);
While I <> 0do
begin
Result[I] := '0';
I := Pos(' ', Result);
end;
end;
function HexToStr(AStr: string): string;
var
I: Integer;
CharValue: Word;
begin
Result := '';
For I := 1 to Trunc(Length(Astr)/2)do
begin
Result := Result + ' ';
CharValue := TransChar(AStr[2*I-1])*16 + TransChar(AStr[2*I]);
Result[I] := Char(CharValue);
end;
end;
function TransChar(AChar: Char): Integer;
begin
if AChar in ['0'..'9'] then
Result := Ord(AChar) - Ord('0')
else
Result := 10 + Ord(AChar) - Ord('A');
end;