本文整理自网络,侵删。
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 firemonkey限制tedit只能输入数字的完美方法
Delphi 系统对话框(如浏览目录)被隐藏到主窗体后面造成程序无法操作的临时处理方式
Delphi unidac 连接mdb access 数据库
Delphi中exit,abort,break,continue 的区别
更多相关阅读请进入《Delphi》频道 >>