Answer
4
The
following C expression computes the logarithm of a 16-bit
number in O(log n) steps, assuming exactly one bit is
set in the number:
(n
& 0xAAAA) ? 1 : 0
|
(n & 0xCCCC) ? 2 : 0
|
(n & 0xF0F0) ? 4 : 0
|
(n & 0xFF00) ? 8 : 0
Contributor: David Tweed
Published
July 2003