Mengubah biNer ke desiMaL...
7:11 AM | Author: aRiany's bLog
Program konversi_Biner_ke_Dec;
uses wincrt;
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.
|
This entry was posted on 7:11 AM and is filed under . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

0 comments: