Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Str (hex int) to Dec Int

Tags:

delphi

I have a hexadecimal string value. I want to convert it to an integer.

function HexStrToInt(const str: string): Integer;
begin
  Result := ??;
end;

such that HexStrToInt('22'), for example, returns 34.

like image 227
Levent Tulun Avatar asked Mar 26 '15 14:03

Levent Tulun


People also ask

How can I convert a hex string to an integer value?

To convert a hexadecimal string to a numberUse the ToInt32(String, Int32) method to convert the number expressed in base-16 to an integer. The first argument of the ToInt32(String, Int32) method is the string to convert. The second argument describes what base the number is expressed in; hexadecimal is base 16.

How do you convert hex to int in Python?

Use int() to Convert Hex to Int in Python If you put 0 as the argument for the base value, it will derive the number format from the value's prefix. If there isn't any prefix, it will automatically recognize it as a decimal, 0b for binary, 0o for octal, and 0x for hexadecimal.


1 Answers

Perhaps the simplest is to do this:

function HexStrToInt(const str: string): Integer;
begin
  Result := StrToInt('$' + str);
end;
like image 85
David Heffernan Avatar answered Sep 23 '22 07:09

David Heffernan