Program Convert_Decimal_To_heksa;
Uses wincrt;
Const N = 100;
Type Stack = record
Isi : Array[1..N]of integer;
Top : integer;
end;
Procedure CreateStack(Var S:Stack);
begin
S.Top := 0;
end;
Function IsFull(S:Stack):boolean;
begin
IsFull := (S.Top = N);
end;
Function IsEmpty(S:Stack):boolean;
begin
IsEmpty := (S.Top = 0);
end;
Procedure Push(X:integer; var S:Stack);
begin
If Not IsFull(S) then
begin
S.Top := S.Top + 1;
S.Isi[S.Top] := X;
end;
end;
Procedure Pop(var X:integer; var S:Stack);
begin
IF NOt IsEmpty(S) then
begin
X := S.Isi[S.Top];
S.Top := S.Top - 1;
end;
end;
Procedure Convert(var S:Stack; X:integer);
var Sisa : integer;
begin
Repeat
Sisa := X mod 16;
X := X div 16;
Push(Sisa,S);
Until X = 0 ;
end;
function rubah (x:integer):string;
begin
if x=10 then
rubah:='A';
if x=11 then
rubah:='B';
if x=12 then
rubah:='C';
if x=13 then
rubah:='D';
if x=14 then
rubah:='E';
if x=15 then
rubah:='F';
end;
{Main Program}
Var S : Stack;
X,i,biner: integer;
biner2:string;
Begin
writeln('+---------------------------------+');
Writeln('|Program Konversi Desimal ke Biner|');
writeln('+---------------------------------+');
Writeln;
Write('Masukkan angka Desimal : ');
readln(X);
writeln;
write('Angka heksadesimal dari ',X,' adalah ');
CreateStack(S);
Convert(S,X);
for i:=1 to S.Top do
begin
Pop(biner,S);
if biner>=10 then
begin
biner2:=rubah (biner);
write(biner2);
end
else
write(biner);
end;
End.
No comments:
Post a Comment