Функция перевода из 10-ой системы счисления в любую в пределах 10 и
функция перевода в 10-ую систему счисления из любой в пределах 10
program sys_count;
function from10ss(x, ss: integer): integer;
var t, d: integer;
begin
t := 1;
d := 0;
while x > 0 do begin
d := d + (x mod ss) * t;
t := t * 10;
x := x div ss;
end;
from10ss := d;
end;
function ss10toX16(_x, _ss: integer): String;
var
oct: integer;
Soct, Sres: String;
begin
Sres := '';
while _x > 0 do begin
oct := _x mod _ss;
case oct of
10: soct := 'A';
11: soct := 'B';
12: soct := 'C';
13: soct := 'D';
14: soct := 'E';
15: soct := 'F';
else
Soct := IntToStr(oct);
end;
Sres := Soct + Sres;
_x := _x div _ss;
end;
ss10toX16 := Sres;
end;
function stepen(x, st: integer): integer;
var i, res: integer;
begin
if st = 0 then begin
stepen := 1;
exit;
end;
res := x;
for i := 2 to st do
res := res * x;
stepen := res;
end;
function to10ss(x, ss: integer):integer;
var r, d: integer;
begin
r := 0;
d := 0;
while x > 0 do begin
d := d + x mod 10 * stepen(ss, r);
inc(r);
x := x div 10;
end;
to10ss := d;
end;
var
osn, n: integer;
begin
osn := 16;
n := 255;
writeln('10 -> 12: ', n, ' = ', ss10toX16(n, osn));
osn := 8;
n := 12;
writeln('10 -> 8: ', n, ' = ', from10ss(n, osn));
osn := 8;
n := 14;
writeln('8 -> 10: ', n, ' = ', to10ss(n, osn));
end.