Jump to content

Non-decimal radices/Convert: Difference between revisions

GP
(→‎{{header|Euphoria}}: Euphoria example added)
(GP)
Line 783:
- : int = 42
</pre>
 
=={{header|PARI/GP}}==
<lang parigp>toBase(n,b)={
my(s="",t);
while(n,
t=n%b;
n\=b;
s=Str(if(t<=9,t,Strchr(Vecsmall([87+t]))),s)
);
if(#s,s,"0")
};
fromBase(s,b)={
my(t=0);
s=Vecsmall(s);
forstep(i=#s,1,-1,
t=b*t+s[i]-if(s[i]<58,48,87)
);
t
};</lang>
 
=={{header|Perl}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.