var
a,b,c,e,f:integer;
d:array [1..255] of integer;
begin
write('input a decimal number! '); readln(a);
write('Binary of decimal ',a,' is: ');
e:=a;
repeat
b:=b+1;
c:= trunc (a/2);
d[b]:=a mod 2;
a:=c;
if (c=1) then
begin
b:=b+1;
d[b]:=1;
end;
until c=1;
for f:=1 to b do
begin
c:= trunc (e/2);
d[f]:=e mod 2;
e:=c;
end;
for f:= b downto 1 do
begin
write(d[f]);
end;
readln
end.
If the program is run:
If there is something not understand, please asked... : )
Hope it is useful, thank you... :)
a,b,c,e,f:integer;
d:array [1..255] of integer;
begin
write('input a decimal number! '); readln(a);
write('Binary of decimal ',a,' is: ');
e:=a;
repeat
b:=b+1;
c:= trunc (a/2);
d[b]:=a mod 2;
a:=c;
if (c=1) then
begin
b:=b+1;
d[b]:=1;
end;
until c=1;
for f:=1 to b do
begin
c:= trunc (e/2);
d[f]:=e mod 2;
e:=c;
end;
for f:= b downto 1 do
begin
write(d[f]);
end;
readln
end.
If the program is run:
input a decimal number! 17 Binary of decimal 17 is 10001 |
If there is something not understand, please asked... : )
Hope it is useful, thank you... :)
0 komentar:
Posting Komentar