delphi HexStrToBytes  
官方Delphi 学习QQ群: 682628230(三千人)
频道

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;

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.043827056884766 seconds