本文整理自网络,侵删。
procedure HexStrToBytes(hHexStr: String; pbyteArray: Pointer);var i, j:WORD; tempPtr:PChar; twoDigits:String[2];begin tempPtr := pbyteArray; j := 1; for i := 1 to (Length(hHexStr) DIV 2) do begin twoDigits:=Copy(hHexStr, j, 2); Inc(j, 2); PByte(tempPtr)^:=StrToInt('$' + twoDigits); Inc(tempPtr); end;end;
// 调用实例 // sOutBuf:array[0..512] of byte; retstr: string; // BytesToHexStr(retstr,@sOutBuf[0],outLen);procedure BytesToHexStr(var hHexStr: String; pbyteArray: PByte; InputLength: WORD);Const HexChars : Array[0..15] of Char = '0123456789ABCDEF';var i, j: WORD;begin SetLength(hHexStr, (InputLength * 2)); FillChar(hHexStr[1], InputLength * 2, #0); j := 1; for i := 1 to InputLength do begin hHexStr[j] := Char(HexChars[pbyteArray^ shr 4]); inc(j); hHexStr[j] := Char(HexChars[pbyteArray^ and 15]); inc(j); inc(pbyteArray); end;end;
相关阅读 >>
Delphi 从indy9升级到indy10时idtcpserver的变化
Delphi 使用webbrowser控件获取含框架的网页的完整html代码
datasnap 上传/下载大文件(本demo以图传片文件为例)
Delphi winapi: writeprivateprofilestring、getprivateprofilestring - 简单读写 ini 文件
更多相关阅读请进入《Delphi》频道 >>