Autor Wiadomość
Ricko
PostWysłany: Wto 20:21, 23 Lis 2010    Temat postu: Konwersje Liczbowe - Pascal

Z 10 NA 2

Cytat:
program z10na2;

uses crt;

var
a,i,j:integer;
t:array[1..20]of integer;

begin
clrscr;

writeln('Podaj a');
readln(a);
i:=1;

if a<>0 then
while a<>0 do
begin
if a mod 2=0 then
t[i]:=0
else
t[i]:=1;

a:=a div 2;
i:=i+1;
end;

for j:=i-1 downto 1 do
write(t[j]);

readln;
readln;
end.


Działanie:
Podana liczba:
Cytat:
21

Wynik:
Cytat:
10101

_____________________________________________________________

Z 2 NA 10

Cytat:
program z2na10;

uses crt;

var
a:string;
i,w:integer;

begin
clrscr;
writeln('Podaj liczbe binarna');
readln(a);
w:=0;

for i:=1 to length(a) do
if a[i]='1' then
w:=w*2+1
else
w:=w*2;

writeln(w);
readln;
end.


Działanie:
Podana liczba:
Cytat:
1010

Wynik:
Cytat:
10

Powered by phpBB © 2001,2002 phpBB Group