Ari Usman Chaniago
Berbagi itu Indah
Program konversi_Biner_to_Dec;
uses crt;
var bilBiner : String;
function pangkat(a, b : integer): integer;
var i, hasil : integer;
begin
hasil := 1;
for i:=1 to b do
begin
hasil := hasil * a;
end;
pangkat := hasil;
end;
function bin2Dec(biner : string) : integer;
var n, sum, i : integer;
begin
n := length(biner);
sum := 0;
for i := n-1 downto 0 do
begin
if (biner [n-1] = ‘0’) then sum := sum + 0 * pangkat (2, i)
else if (biner [n-1] = ‘1’) then sum := sum + 1 * pangkat (2, i);
end;
bin2Dec := sum;
end;
begin
clrscr;
writeln(‘KONVERSI BILANGAN BINER KE DESIMAL’);
writeln;
write(‘Masukkan bilangan Biner : ‘);readln(bilBiner);
write (‘Bilangan Desimalnya : ‘, bin2Dec(bilBiner));
readkey;
end.