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 时间与相关类型(2) - tdate、ttime、ttimestamp

Delphi �o置系�y�r�g

Delphi 获取 access 数据库所有表

Delphi wmi 取显卡gpu信息

Delphi 多次改变 richedit.text部份文本的颜色后,出现所有字体都变色的的解决办法

Delphi 采集功能代码getstr

Delphi xe [dcc32 fatal error] f2039 could not create output file 问题的解决

Delphi 生成txt 指定带bom

Delphi 精确打印image画布

Delphi来实现全屏截图

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



打赏

取消

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

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

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

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

评论

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