PASCAL : Konversi Desimal ke Biner

Ini adalah cara mengonversi desimal ke biner pada pascal

****

Program dectobin;
uses wincrt;
var
hasilbagi, desimal,sisa: integer;
biner,bin, bilbiner: string;
begin
write (‘Desimal= ‘);
read (desimal);
hasilbagi:= desimal div 2;
bilbiner := ‘ ‘;
while (hasilbagi >= 1 ) do
begin
sisa := desimal mod 2;
if (sisa=0) then biner := ‘0’ else
if (sisa=1) then biner := ‘1’;
bilbiner := biner+bilbiner;
desimal := hasilbagi;
hasilbagi := desimal div 2;
end;
bin := ‘1’ + bilbiner;
writeln (‘hasilbiner = ‘, bin);
end.

Advertisements

4 thoughts on “PASCAL : Konversi Desimal ke Biner

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s