Possible Duplicate:
How to find a binary logarithm very fast? (O(1) at best)
how does the log function work. How the log of a with base b is calculated.
Possible Duplicate:
How to find a binary logarithm very fast? (O(1) at best)
how does the log function work. How the log of a with base b is calculated.
There are many algorithms for doing this. One of my favorites (WARNING: shameless plug) is this one based on the Fibonacci numbers. The code contains a pretty elaborate comment that goes into how the math works. Given a and ab, it runs in time O(lg b) and O(1) space.
Hope this helps!