unsigned int v; // 32-bit word to find the log base 2 of
unsigned int r = 0; // r will be lg(v)

while (v >>= 1) // unroll for more speed...
{
  r++;
}

http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious


-

Azhar.


On Thu, Jun 14, 2012 at 12:48 PM, Anika Jain <[email protected]> wrote:

> sorry note its right shifting in my above post instead of left shift!
>
>
> On Thu, Jun 14, 2012 at 12:47 PM, Anika Jain <[email protected]>wrote:
>
>> keep on left shifting the number till it becomes 0. the moment it becomes
>> 0, the count of how many times you had to right shift the number to get 0
>> is the answer.
>>
>>
>> On Thu, Jun 14, 2012 at 11:45 AM, Krishna Kishore <
>> [email protected]> wrote:
>>
>>> How to find the LEFT MOST set bit in an unsigned integer.
>>> Example:
>>> "00*1*0 0001 0100 0010" is a 16-bit unsigned integer. We have to find
>>> the left most set bit position (Starting with 0 from right side )
>>> which is 13th position in our example. How to find this. Can any one pls
>>> give any suggestions.
>>> Thank You Very Much In Advance.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msg/algogeeks/-/HJnuFujMZ3wJ.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected].
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>> Regards
>> Anika Jain
>>
>>
>
>
> --
> Regards
> Anika Jain
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to