Convert hex str to decimal value in delphi

前端 未结 4 721
清歌不尽
清歌不尽 2021-01-18 01:24

I\'ve got a problem to convert a string representation of an hex value in integer value with Delphi.

for example:

$FC75B6A9D025CB16 give me 8

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-18 02:12

    I had to use a Delphi library named "DFF Library" because I work on Delphi6 and the type Uint64 does not exist in this version.
    Main page

    Here's my code to transform a string of hexadecimal value to a string of decimal value:

    You need to add UBigIntsV3 to your uses in your unit.

    function StrHexaToUInt64Str(const stringHexadecimal: String): string;
    var
      unBigInteger:TInteger;
    begin
      unBigInteger:=TInteger.Create;
      try
        // stringHexadecimal parameter is passed without the '$' symbol
        // ex: stringHexadecimal:='FFAA0256' and not '$FFAA0256'
        unBigInteger.AssignHex(stringHexadecimal);
        //the boolean value determine if we want to add the thousand separator or not.
        Result:=unBigInteger.converttoDecimalString(false);
      finally
        unBigInteger.free;
      end;
    end;
    

提交回复
热议问题