trata con ese codigo...
Con estas dos funciones podemos convertir números a otras bases (Hexadecimal, Octal, binario, etc)
-Pon un TMemo (Memo1) y un TButton (Button1) en tu form
-Pon este código en el OnClick del Button1:
procedure TForm1.Button1Click(Sender: TObject);
const B36 : PChar = ('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ');
function IntToBase(iValue: integer; Base: byte; Digits: byte): string;
begin
result := '';
repeat
result := B36[iValue mod BASE]+result;
iValue := iValue div Base;
until (iValue div Base = 0);
result := B36[iValue mod BASE]+result;
while length(Result) < Digits do Result := '0' + Result;
end;
function BaseToint(iValue: String; Base: byte): integer;
var
i: byte;
begin
result := 0;
for i := 1 to length(iValue) do begin
if (pos(iValue[i], B36)-1) < Base then
result := result * Base + (pos(iValue[i], B36)-1)
else begin
result := 0;
break;
end;
end;
end;
var
n : integer;
begin
{Un ejemplo: mostramos decimal, Hexadecimal y Octal}
{An example, shows Decimal, Hexadecimal and Octal}
for n:= 0 to 500 do begin
Memo1.Lines.Add( 'Dec:'+IntToStr(n)+^I+
'Hex:'+IntToBase(n,16,3)+^I+
'Oct:'+IntToBase(n,8,3) );
end;
end;
__________________
ing. frankmch
|