El siguiente código muestra como convertir un numero entero muy largo, por ejemplo de 100 cifras, a hexadecimal o binario
php
type function parseBigInt(str: String): TBigInt; var i, l: Integer; begin if Length(str) = 0 then raise Exception.Create('Invalid integer value'); while (Length(str) > 1) and (str[1] = '0') do delete(str, 1, 1); l:= Length(str); SetLength(Result, l); for i:= 1 to l do Result[l - i]:= StrToInt(str[i]); end; function div2(bigInt: TBigInt): TBigInt; var i, j, rem: Integer; begin rem:= 0; for i:= High(bigInt) downto Low(bigInt) do begin j:= rem + bigInt[i]; bigInt[i]:= j div 2; rem:= (j mod 2) * 10; end; Result:= bigInt; end; function bigIntOdd(bigInt: TBigInt): Boolean; begin if Length(bigInt) < 1 then Result:= True else Result:= Odd(bigInt[Low(bigInt)]); end; function isZero(bigInt: TBigInt): Boolean; var i: Integer; begin Result:= True; for i:= Low(bigInt) to High(bigInt) do if bigInt[i] <> 0 then begin Result:= False; Exit; end; end; function bigIntToBinary(bigInt: TBigInt): String; begin Result:= ''; while not isZero(bigInt) do begin if bigIntOdd(bigInt) then Result:= '1' + Result else Result:= '0' + Result; bigInt:= div2(bigInt); end; end; function binaryToHex(binary: String): String; var i,j,k: Integer; nibble: String; begin Result:= ''; while Length(binary) mod 4 <> 0 do binary:= '0' + binary; if Length(binary) = 0 then begin Result:= '0'; Exit; end; for i:= 0 to (length(binary) div 4) - 1 do begin k:= 0; for j:= 1 to length(nibble) do begin k:= k * 2; if nibble[j] = '1' then k:= k + 1; end; Result:= Result + IntToHex(k, 1); end; end;
Por ejemplo esto
php
Writeln(binaryToHex(bigIntToBinary(parseBigInt('9876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210'))));
Genera esto a la salida
php
120FE0BCDADD3B9A1BD4E0782C2D3E04397663BB69D67059E9426DD4733C9B4067DED51E67D751C67EEA
Saludos