Here is the code i wrote for a challenge:

Code:
alias base2 {
  var %a 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ, %i -1, %t, %r 
  while $mid($1,%i,1) >= 0 {
    inc %t $calc(($pos(%a,$ifmatch)-1)*$2 ^-(%i +1)) 
    dec %i
  }
  while $int(%t) >=0 {
    %r = $mid(%a,$calc(%t % $3 +1),1) $+ %r 
    %t = %t / $3 
  } 
  return %r
}


It starts by converting the given number in base 10, then convert the base 10 number in given base

To convert hexadecimal (base16) in decimal (base 10):
29A = 2 9 10
29A = 2*(16^2) + 9*(16^1) + 10*(16^0)
29A = 666

To convert binary (base2) in decimal(base10):
10010 = 1 0 0 1 0
10010 = 1*(2^4) + 0*(2^3) + 0*(2^2) + 1*(2^1) + 0*(2^0)

Then, if you want to convert a base 10 into a base 16:
echo -a $base(666,10,16) = 29A

int(666 / (16 ^ 0)) % 16 = 10 = A
int(666 / (16 ^ 1)) % 16 = 9 = 9
int(666 / (16 ^ 2)) % 16 = 2 = 2
Then you read the number backwards... tada!! 29A

With that, you should be able to understand how the snippet work!