Mengubah desiMaL ke biNer...
12:29 PM | Author: aRiany's bLog
Program konversi_Desimal_ke_Biner;
uses crt;
var bilangan:integer;

function decToBin(desimal:integer):string;
var hasilbagi, sisa:integer;
bin:char;
bilBiner:string;
begin
hasilBagi := desimal div 2;
bilBiner := '';

while (hasilBagi >= 1) do
begin
sisa := desimal mod 2;
if (sisa = 0)then bin := '0'
else if (sisa = 1) then bin := '1';

bilBiner:=bin + bilBiner;

desimal := hasilBagi;
hasilBagi := desimal div 2;
end;
decToBin:='1' + bilBiner;
end;

begin
clrscr;
writeln('KONVERSI BILANGAN DESIMAL KE BINER');
writeln;
write('masukkan bilangan : ');readln(bilangan);
write('Bilangan Binernya : ', decToBin(bilangan));
readkey;
end.
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.