Delphi intToHex


本文整理自网络,侵删。

 
看了下10.3.2版intToHex等,跟之前的xe版比较,去掉了汇编,我试了下,变慢了好多,自己写些了个,纯pascal版,测了下,要比自带的函数快差不多一倍,比xe汇编版也快很多

做了点优化,大概计算时间是Delphi 10.3.2自带函数的三分之一计算时间

function intToHexA(iValue: Cardinal; Digits: Integer): string;
const
  hexChar: array[0..15] of char = '0123456789ABCDEF';
var
  d: Integer;
  i: Integer;
  hexLen: Integer;
  pc: PChar;
begin
  if iValue = 0 then
  begin
    Result := StringOfChar('0', Digits);
  end
  else
  begin
    hexLen := 0;

    for I := 0 to 7 do
    begin
      if ((iValue shr (i shl 2)) and $F) <> 0 then
        hexLen := i + 1;
    end;

    if hexLen > Digits then
      Digits := hexLen;

    SetLength(Result, Digits);
    pc := pchar(Result) + Digits - 1;
    //
    for i := 0 to hexLen - 1 do
    begin
      d := (iValue shr (i shl 2)) and $F;

      pc^ := hexChar[d];
      dec(pc);
    end;

    for I := 0 to (Digits - hexLen) - 1 do
    begin
      pc^ := '0';
      dec(pc);
    end;
  end;
end;

来源:http://bbs.2ccc.com/topic.asp?topicid=575175

相关阅读 >>

Delphi 的tstringbuilder防止服务器内存碎片化

Delphi制作外挂的操作技巧

Delphi 计算一个路径相对于另一路径的相对路径

Delphi trim删除字符串首尾空格

Delphi 取16进制字符的10进制的integer值

Delphi inttohex

Delphi 处理链接和文件路径结尾\和/

Delphi firedac 连接sql server一些要注意的地方

Delphi 注入不用writeprocessmemory 函数

Delphi http协议验证访问datasnap rest 服务器

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



打赏

取消

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

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

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

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

评论

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