it is
3*2^12 + 15*2^8 + 3*2^4 + 3
so it becomes
3<<12 + 15<<8 + 3<<4 +3.. let this equal to n
take a int count=0;
while(n){
n=n&(n-1);
count++;
}
return count;
2010/8/4 Seçkin Can Şahin <[email protected]>
> either count it with a for loop or if you are using C, use
> __builtin_popcount(int x)
>
> or
>
> x is given
> int count = 0;
> for(int i=0; i<32;i++) count += (x & (1<<i)) != 0;
>
>
> On Tue, Aug 3, 2010 at 12:04 PM, amit <[email protected]> wrote:
>
>> (3*4096+15*256+3*16+3). How many 1's are there in the binary
>> representation of the result.
>>
>> Is there a quick way to count the number of set bits in this number
>> manually???
>>
>> --
>> 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]<algogeeks%[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]<algogeeks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
With Regards,
Jalaj Jaiswal
+919026283397
B.TECH IT
IIIT ALLAHABAD
--
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.