In [1]:
function to_dec(b,x)
    ret = 0
    pos = 0
    while x >= 10^pos
        digit = Int(trunc((x % (10^(pos+1)))/(10^pos)))
        ret += digit * b^pos
        pos += 1
    end
    return ret
end


Out[1]:
to_dec (generic function with 1 method)

In [2]:
println("5240 base 6 in decimal is ", to_dec(6, 5240))
println("12012 base 3 in decimal is ", to_dec(3, 12012))
println("888 base 9 in decimal is ", to_dec(9, 888))


5240 base 6 in decimal is 1176
12012 base 3 in decimal is 140
888 base 9 in decimal is 728

In [3]:
function cnt_dgt(b,x)
    pos = 0
    while (x / b^pos) > 1
        pos += 1
    end
    return pos
end


Out[3]:
cnt_dgt (generic function with 1 method)

In [4]:
for i in 2:9
    println("1111 base 10 needs ", cnt_dgt(i, 1111), " digits in base ", i)
end


1111 base 10 needs 11 digits in base 2
1111 base 10 needs 7 digits in base 3
1111 base 10 needs 6 digits in base 4
1111 base 10 needs 5 digits in base 5
1111 base 10 needs 4 digits in base 6
1111 base 10 needs 4 digits in base 7
1111 base 10 needs 4 digits in base 8
1111 base 10 needs 4 digits in base 9

In [ ]: