function TForm1.myStrToHex(s:string):string; //字串转16进制
var
TmpStr:string;
i:integer;
begin
TmpStr:='';
for i:=1 to Length(s)do
begin
TmpStr:=TmpStr+IntToHex(ord(s[i]),2);
end;
Result:=TmpStr;
end;
function TForm1.myHexToStr(s:string):string; //16进制转字串
var
HexS,TmpStr:string;
i:Integer;
a:Byte;
begin
HexS:=s;
if Length(HexS) mod 2=1 then
begin
HexS:=HexS+'0';
end;
TmpStr:='';
for i:=1 to(Length(HexS)div 2)do
begin
a:=StrToInt('$'+HexS[2*i-1]+HexS[2*i]);
TmpStr:=TmpStr+Chr(a);
end;
Result:=TmpStr;
end;
摘抄自http://blog.csdn.net/chinazhd/article/details/7578412,转载一份自己留作备忘