Well as Bekar said, $base() will do this for you. But if you just want to know how or intend to do something else that prevents you using $base() here's the code anyway:
convert {
var %input = $1, %base = $2, %r
while %input {
%r = $+($calc(%input % %base),%r)
%input = $int($calc(%input / %base))
}
return %r
}
In particular you might want to note the use of the modulus operator (
%) which returns the remainder of division between two numbers