Board index » delphi » Hex to Decimal?

Hex to Decimal?

Is there a function available to convert from Hex to Decimal? The
closest I can get is the format function but that is next to useless. I
don't really wish to try and write my own routine as I figured there
would be one lying around somewhere.

Any help would be greatly appreciated.
Thanx.
---------
Benjamin
"Control your life through insanity" - Cliff Burton R.I.P
"What happened to this song we once knew so well?"
E-mail: bw...@ironbark.bendigo.latrobe.edu.au
URL: http://ironbark.bendigo.latrobe.edu.au/~bwes1/
----------------------------------------------------------------

 

Re:Hex to Decimal?


// This function converts a string of hexadecimal characters into an
integer.
// Example: HexToInt('FF') returns 255.

function HexToInt(const Value: String): Integer;

begin
  Result := StrToInt('$' + Value);
end;

Quote
Benjamin West wrote in message

<37984CE7.D34C1...@ironbark.bendigo.latrobe.edu.au>...
Quote
>Is there a function available to convert from Hex to Decimal? The
>closest I can get is the format function but that is next to useless. I
>don't really wish to try and write my own routine as I figured there
>would be one lying around somewhere.

Re:Hex to Decimal?


The 'Val' procedure handles hex numbers if they start with a '$'.

Val('255',i,Err)  ==> i = 255, Err = 0
Val('$FF',i,Err)  ==> i = 255, Err = 0
Val('ABC',i,Err)  ==> i =   0, Err = 1
Val('1BC',i,Err)  ==> i =   1, Err = 2

Quote
Benjamin West wrote:

> Is there a function available to convert from Hex to Decimal? The
> closest I can get is the format function but that is next to useless. I
> don't really wish to try and write my own routine as I figured there
> would be one lying around somewhere.

> Any help would be greatly appreciated.
> Thanx.

-----------------------------------------------------------------
Quote
>> > Tired of messy email and newsgroup messages mangled by
>> cascading
>> > indentation and improper word wrap? Try the MessageCleaner
>> utility.
>> > Download it now at:

-----------------------------------------------------------------
http://www.RoundhillSoftware.com/MessageCleaner
-----------------------------------------------------------------

Re:Hex to Decimal?


IntNumber := StrToInt('$' + MyHexVarString);
Edit1.Text := IntToStr(IntNumber);

Assuming you mean a hex STRING.  There is no distinction in programming for
hex vs decimal except, or course, in the code assignment.

Steve

--
Fix my email address to reply directly.

Quote
Benjamin West wrote in message

<37984CE7.D34C1...@ironbark.bendigo.latrobe.edu.au>...
Quote
>Is there a function available to convert from Hex to Decimal? The
>closest I can get is the format function but that is next to useless. I
>don't really wish to try and write my own routine as I figured there
>would be one lying around somewhere.

Other Threads