本文整理自网络,侵删。
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;function StrToHex(AStr: string): string;var I ,Len: Integer; s:char;begin len:=length(AStr); Result:=''; for i:=1 to len do begin s:=AStr[i]; Result:=Result +' '+IntToHex(Ord(s),2); //将字符串转化为16进制字符串, //并以空格间隔。 end; Delete(Result,1,1); //删去字符串中第一个空格end;function HexToStr(AStr: string): string;var I,len : Integer; CharValue: Word; Tmp:string; s:char;begin Tmp:=''; len:=length(Astr); for i:=1 to len do begin s:=Astr[i]; if s <> ' ' then Tmp:=Tmp+ string(s); end; Result := ''; For I := 1 to Trunc(Length(Tmp)/2) do begin Result := Result + ' '; CharValue := TransChar(Tmp[2*I-1])*16 + TransChar(Tmp[2*I]); if (charvalue < 32) or (charvalue > 126) then Result[I] := '.' //非可见字符填充 else Result[I] := Char(CharValue); end;end;
来源:https://www.cnblogs.com/tc310/p/4587287.html
相关阅读 >>
Delphi winapi: flashwindow - 闪烁窗口
Delphi fileopendialog1 多选加载大量文件,不受中文文件名影响
Delphi 分解时间 �cdecodedate、decodetime … decodedatetime …
在Delphi xe6 firemonkey移动应用程序的twebbrowser html页面上运行javascript
更多相关阅读请进入《Delphi》频道 >>