Senin, Juni 13, 2016

Pascal Programming Convert Decimal (Base 10) to Binary (Base 2)

var
a,b,d,e,f:integer;
c:array[1..255] of integer;

begin
write('input a decimal number! ');
readln(a);
write('binary of decimal ',a,' is ');

if a<=1 then write(a) else

repeat
 b:=b+1;
 d:=trunc(a/2);
 c[b]:=a mod 2;
 if d<=1 then
 begin
  b:=b+1;
  c[b]:=d;
 end;
 a:=d;
until d<=1;

for e:=b downto 1 do
begin
 write(c[e]);
end;

readln
end.

please check at http://www.convertworld.com/id/angka/Desimal.html

0 komentar: