It works something like this:
import string
allChars = string.digits+string.lowercase #get a list of all the 'characters' which represent digits
def toInt(srep,base):
charMap = dict(zip(allChars,range(len(allChars)))) #map each 'character' to the base10 number
num = 0 #the current total
index = len(srep)-1 #the current exponent
for digit in srep:
num += charMap[digit]*base**index
index -= 1
return num
The process with some debugging print for interpreting 'a16' would be:
>>> int('a16',16) #builtin function
2582
>>> toInt('a16',16)
+=10*16^2 -> 2560
+=1*16^1 -> 2576
+=6*16^0 -> 2582
2582