Ver Mensaje Individual
  #9  
Antiguo 15-11-2017
Javier13 Javier13 is offline
Miembro
NULL
 
Registrado: jun 2017
Posts: 34
Reputación: 0
Javier13 Va por buen camino
Así va mi codigo:

function Conversion(Numero, desde, hasta: string): string;
var
k : Integer; //ya
n : Integer; //creo
digito : string;
valor : Integer;
pos : Integer;
alfabeto : String;//TStringList;
alfalis : TStringList;
maximo : Integer;
p : Integer;
resultado : String;
actual : Real;
division : integer;
//z : extended;
resta : integer;
resultadok: Real;
indice : string;
begin
// Round : redondea un Número de punto flotante a un valor entero.
// Length :
// Power : Potencia
// div : Divicion entera
// Mod : Modulo o resuduo

alfabeto:='abcdefghijklmnñopqrstuvwxyz';
maximo:=Length(alfabeto);


if not (StrToInt(desde) < maximo) and (StrToInt(desde) >1) then begin
Showmessage('Base origen imposible');
Exit;
end;

if not (StrToInt(hasta) < maximo) and (StrToInt(hasta) >1) then begin
Showmessage('Base destino imposible');
Exit;
end;

k:=0;
n:= Length(Numero);

for pos in [0..n] do begin
digito:=numero[pos];
end;

if not (edNumero.Text<> digito) and (edNumero.Text<>alfabeto)then begin
Showmessage(Digito + ' No es valido en ninguna base');
Exit;
end;
{ valor:=alfabeto.IndexOf(digito); }

if not valor < StrToInt(desde) then begin
Showmessage(Digito + ' No es valido en base origen');
Exit;
end;

k:= valor*StrToInt(desde);
resta:= (n - pos - 1);
resultadok:= Power(k,resta);
p:=0;

while hasta < IntToStr(k) do begin
p:= p+1;
resultado:= '';
end;

while p > 0 do begin
p:=p-1;
actual:= (power(StrToInt(hasta),p));
resultado:=resultado+alfabeto+IntToStr((k div Round(actual)));
k:= k mod Round(actual);
Result:=resultado;
end;
end;
Responder Con Cita