niepok

conversion of number systems

Jan 25th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.31 KB | None | 0 0
  1. program systemy;
  2. uses crt,math;
  3. var
  4.   system_wejscie,system_wyjscie,liczba,j,i,reszta:integer;
  5.   tab,wynik,znak:string;
  6. begin
  7.   write ('wprowadz w jakim systemie wprowadzasz liczbe: ');
  8.   readln (system_wejscie);
  9.   write ('wpisz liczbe: ');
  10.   readln (tab);
  11.   j:=0;
  12.   liczba:=0;
  13.   for i:=Length(tab) downto 1 do
  14.        begin
  15.          if (ord(tab[i])<ord('A')) then
  16.             begin
  17.               liczba:=round(liczba+(ord(tab[i])-48)*power(system_wejscie,j));
  18.             end;
  19.          if (ord(tab[i])>=ord('A')) then
  20.             begin
  21.               liczba:=round(liczba+(ord(tab[i])-ord('A')+10)*power(system_wejscie,j));
  22.             end;
  23.          j:=j+1;
  24.        end;
  25.   write('W jakim chcesz wyprowadzic:') ;
  26.   readln (system_wyjscie);
  27.  repeat
  28.      reszta:=liczba mod system_wyjscie;
  29.      if(reszta=10) then
  30.      znak:='A' else if(reszta = 11) then
  31.      znak:='B' else if(reszta = 12) then
  32.      znak:='C' else if(reszta = 13) then
  33.      znak:='D' else if(reszta = 14) then
  34.      znak:='E' else if(reszta = 15) then
  35.      znak:='F' else str(reszta,znak);     // zmiana reszta (int na string) i podstawienie w zmiennej znak
  36.      insert(znak,wynik,1);                // umieszczenie znak w stringu wynik na poz 1
  37.      liczba:=liczba div system_wyjscie;
  38.    until(liczba=0) ;
  39.    writeln(wynik);
  40.    readkey;
  41. end.
Advertisement
Add Comment
Please, Sign In to add comment