Convert hex str to decimal value in delphi

前端 未结 4 722
清歌不尽
清歌不尽 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:05

    In fact 802829546 is clearly wrong here.

    Calc returns a 64bit unsigned value (18191647110290852630d).

    Delphi Int64 type uses highest bit as sign:

    Int := StrToInt64('$FC75B6A9D025CB16');
    Showmessage(IntToStr(Int));
    

    returns value -255096963418698986 which is correct

    If you need to work with values larger than 64bit signed, then check out Arnaud's answer here.

提交回复
热议问题