Anda di halaman 1dari 2

PROGAM KONVERSI BILANGAN DESIMAL KE BINER DAN HEXADESIMAL

=====================================================================
===============================================
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
a:array[1..99] of word;
i,k,d:word;
begin
edit2.Clear;
d:=strtoint(edit1.Text);
k:=0;
While d>=2 do begin//untuk dec to oct 2 diganti 8
k:=k+1;
a[k]:=d mod 2; //untuk dec to oct 2 diganti 8
d:=d div 2; //untuk dec to oct 2 diganti8
end;
k:=k+1;
a[k]:=d;
for i:=k downto 1 do
edit2.Text:=edit2.text+inttostr(a[i]);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
a:array[1..99] of word;
i,k,d:word;
c:shortstring;
begin
edit2.Clear;
d:=strtoint(edit1.Text);
k:=0;
While d>=16 do begin

k:=k+1;
a[k]:=d mod 16;
d:=d div 16
end;
k:=k+1;
a[k]:=d;
for i:=k downto 1 do begin
case a[i] of
10:c:='A';
11:c:='B';
12:c:='C';
13:c:='D';
14:c:='E';
15:c:='F';
16:c:='G';
else C:=inttostr(a[i]);
end;
edit2.Text:=edit2.Text+c;
end;
end;
end.
=====================================================================
===============================================
Capture from:
Main Form

Capture from:
Saat progam dijalankan

Anda mungkin juga menyukai