- Ambil sebuah label dan sebuah button. kemudian letakkan seperti gambar dibawah ini.
- Setelah itu, klik dua kali pada button1, kemudian masukkan kodingan dibawah ini.
unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, math;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Strhexadecimal : String;
IntIndex : Integer;
IntPlaceValue : Integer;
ChrAlpha : Char;
IntDigit : Integer;
IntTotal : Integer;
StrDecimal : String;
begin
Strhexadecimal := Edit1.Text;
IntTotal := 0;
IntPlaceValue := Round(Power(16, (Length(Strhexadecimal)-1)));
for IntIndex := 1 to Length(Strhexadecimal)
do
begin
ChrAlpha := Strhexadecimal[IntIndex];
If ((ChrAlpha >= '0')
and (ChrAlpha <= '9'))
then
begin
IntDigit := StrToInt(ChrAlpha);
end
else
begin
If ((ChrAlpha >= 'A')
and (ChrAlpha <= 'F'))
then
begin
IntDigit := Ord(ChrAlpha) - 55;
end
else
begin
Raise Exception.Create(ChrAlpha + ' is not a valid hexadecimal digit.');
end;
end;
IntTotal := IntTotal + (IntDigit * IntPlaceValue);
IntPlaceValue := Round(IntPlaceValue / 16);
end;
StrDecimal := IntToStr(IntTotal);
ShowMessage(Strhexadecimal + ' DALAM HEXADESIMAL, ADALAH ' + StrDecimal + ' DALAM DESIMAL.');
end;
end.