How to convert Hex to Int?

I have hex strings '00001A7000000000' ... '00001A700000012D'
how to convert each of them to unique integer
selasAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GreybirdCommented:
You should try :

function hexaToInt(s : string) : Int64;
begin
  if (s <> '') and (s[1] <> '$') then
    result := strToInt64('$' + s)
  else
    result := strToInt64(s);
end;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
illusion_chaserCommented:
Try this one:

function HexToInt2(s: string): Int64;
var
  b: Byte;
  c: Char;
begin
  Result := 0;
  s := UpperCase(s);
  for b := 1 to Length(s) do
  begin
    Result := Result * 16;
    c := s[b];
    case c of
      '0'..'9': Inc(Result, Ord(c) - Ord('0'));
      'A'..'F': Inc(Result, Ord(c) - Ord('A') + 10);
      else
        raise EConvertError.Create('No Hex-Number');
    end;
  end;
end;
GreybirdCommented:
What is the point of recoding a function that is in the VCL ?
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

illusion_chaserCommented:
Where in the VCL?
It was taken from torry's site.
And that is an alternative solution.
GreybirdCommented:
The function is StrToInt64, available in the SysUtils unit. You just have to prefix the string by $ pr 0x to tell this function the string you pass is hexa...
Ok for the alternative solution, but IMHO, when something is already available, you should bother recoding your own, except for a very good reason...
illusion_chaserCommented:
I think, we should let the Author decide what solution suites his needs better. BTW, your solution will work only in Delphi, while the logic that I posted (with minor changes) will work in other programming languages (and that is the good reason).
GreybirdCommented:
Right, he should decide.

However, we are in the Delphi section, not in the Programming one, so I suspects that he wants a Delphi solution ;)
Lee_NoverCommented:
agree with Greybird .. although there is one small caveat .. the letters must be lowercase :)
selasAuthor Commented:
if i use:

function hexaToInt(s : string) : Int64;
begin
  if (s <> '') and (s[1] <> '$') then
    result := strToInt64('$' + s)
  else
    result := strToInt64(s);
end;

How to convert this integer back to HexString?

e.g. 00001A7000000000 = 29068338659328
      29068338659328 = 00001A7000000000
Lee_NoverCommented:
use Format('%x', [29068338659328])
selasAuthor Commented:
if i use format i get: 1A7000000000
GreybirdCommented:
In fact you should use :
Format('%.16x', [29068338659328])
to get the padding 0s.
Lee_NoverCommented:
yeah .. it helps to read the help .. weird sentence :D
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.