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:
Code:
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


Spelling mistakes, grammatical errors, and stupid comments are intentional.