
31.05.2007, 22:16
|
|
Постоянный
Регистрация: 11.03.2007
Сообщений: 581
Провел на форуме: 4172659
Репутация:
646
|
|
Код:
const
alf = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
function power(x,y: integer): int64;
begin
if x = 0 then
result := 0
else
result := trunc(exp(ln(x)*y));
end;
function fromdec(d: int64; s: integer): string;
begin
if (d < s) then
result := alf[d + 1]
else
result := fromdec(d div s,s) + alf[d mod s + 1];
end;
function todec(d: string; s: integer): int64;
begin
if length(d) = 1 then
result := pos(d,alf) - 1
else
result := (pos(d[1],alf) - 1) * power(s, length(d)-1) + todec(copy(d,2,length(d)-1),s);
end;
Delphi. Системы счисления. 2 <= s <= 36
З.Ы. Рекурсия рулит
|
|
|