# Board index » delphi » Converting Hex to Decimal (Newbie Question)

## Converting Hex to Decimal (Newbie Question)

Hi,

I'm a Delphi beginner looking for some help with writing a very simple
program.  I need to convert a hexadecimal number into a decimal one
and display the result on screen, but I'm not quite sure how to!  Can
someone point me in the right direction?

Cheers,

John.
----------
http://welcome.to/parrot

## Re:Converting Hex to Decimal (Newbie Question)

Hi John

Just as StrToInt can convert '1234' into 1234 it can convert '\$1234' into
4660 so just concatenate '\$' in front of your value in a string variable.
It's limited to the values of a LongInt.

Try this code on a form with an Edit and a Label on it:

procedure TForm1.Edit1Change(Sender: TObject);
var
L : LongInt;
begin
try
L :=  StrToInt('\$'+Edit1.Text);
Label1.Caption := IntToStr(L);
except
Label1.Caption := 'Not a legal hex value';
end;
end;

Cheers /Jesper

## Re:Converting Hex to Decimal (Newbie Question)

On Fri, 07 Jan 2000 21:41:44 -0600, Mark Edwards <medwa...@onramp.net>
posted something but I'd had too much Tequila to remember how to reply
so I left it 'til now:

##### Quote
>No cluons were harmed when John McGarvey <redm...@eidosnet.co.uk>
>said:

>>I'm a Delphi beginner looking for some help with writing a very simple
>>program.  I need to convert a hexadecimal number into a decimal one
>>and display the result on screen, but I'm not quite sure how to!  Can
>>someone point me in the right direction?

<snippety>

Thanks to both posters who responded; I got the program working fine
:-)

Cheers,

John.
----------
http://welcome.to/parrot

## Re:Converting Hex to Decimal (Newbie Question)

##### Quote
>I'm a Delphi beginner looking for some help with writing a very simple
>program.  I need to convert a hexadecimal number into a decimal one
>and display the result on screen.

*********
all integers are stored in memory as hexadecimals.

n := \$A0 ; // n is an integer
caption := format('Decimal = %d  Hex = %x ',[n,n]);  // display in dec & hex
form.

chaoo,
noordin