Algoritma - Conversi Biner ke Decimal

{Conversi Biner Ke Decimal}
Source Code =>

Program Bin-Dec;
uses crt;
var
biner, b : string [10];
a, c, d, dec : byte;
begin
clrscr;
write ('Masukkan bilangan biner [8 Bit Recomended]:');
readln (biner);
for a := length(biner)-1 downto 0 do
begin
b := copy (biner, length(biner)-a ,1);

if b = '1' then
begin

c := 1;
if a = 0 then c := 1
else if a>0 then
begin
for d := 1 to a do
begin
c := c * 2
end;
end;

dec := dec + c;
end;
end;
writeln;
writeln ('Bilangan decimal dari bilangan ',biner, '=', dec);
readln;
end.

Komentar

Postingan Populer