Delphi HexStrToBytes


本文整理自网络,侵删。

 
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判断某一个点是否在一个区域内

monthoftheyear:取得一个tdatetime变量的月份在年度中的索引

Delphi 一个拼图工具的制作思路

Delphi用内存流方式获取页面验证码图片

Delphi 获取所有磁盘分区另类方法

winsock 实现telnet后门

winapi 字符及字符串函数(12): lstrlen - 串长度

Delphi 将鼠标锁定在一定范围

Delphi listbox自动获取列表框中的组件焦点

Delphi外挂编写

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...