How to find a binary logarithm very fast? (O(1) at best)

Posted by psihodelia on Stack Overflow See other posts from Stack Overflow or by psihodelia
Published on 2010-04-19T14:34:50Z Indexed on 2010/04/19 14:53 UTC
Read the original article Hit count: 429

Is there any very fast method to find a binary logarithm of an integer number? For example, given a number x=52656145834278593348959013841835216159447547700274555627155488768 such algorithm must find y=log(x,2) which is 215. x is always a power of 2.

The problem seems to be really simple. All what is required is to find the position of the most significant 1 bit. There is a well-known method FloorLog, but it is not very fast especially for the very long multi-words integers.

What is the fastest method?

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about numerical-methods