algorithm for unsinged integer (at the moment)
base choices 2 to 36
program bases;
var
u,i,n:longword;
base:byte;
s:pchar;
//libc.so linux
function ultoa(T:longword;F:pointer;sz:integer):pchar ;cdecl external 'msvcrt.dll' name '_ultoa';
function strtoul (s:pchar;b:pointer;L: longint):longword ;cdecl external 'msvcrt.dll' name 'strtoul';
function uintToBase(N:longword;_base:byte):pchar;
var
s:ansistring;
buffer:pchar;
begin
setlength(s,50);
buffer:=@s[1];
ultoa(n,buffer,_base);
result:= (buffer)
end;
function uintFromBase(s:pchar;_base:byte):longword ;
begin
result:= strtoul(s,nil,_base);
end;
begin
base:=12;
for i:=1 to 40 do
begin
n:=random(5000000);
s:=uintTobase(n,base);
u:=uintFromBase(s,base);
writeln('num = ',n,' base ',base,' = ',s,' return = ',u,' compare ',n=u );
end;
writeln('press enter to end . . .');
readln;
end.
For signed floats a project beckons.
Sorry for the un formatted writeln
Dev-Pas ide. tested 32 and 64 bits fp 3.04