how abt my code
#includestdio.h
int count1bitsn(int n)
{
int count=0;
while(n)
{
count+=n1;
n=n1;
}
}
int main()
{
int n;
printf(Enter the value of n\n);
scanf(%d,n);
how abt my code
#includestdio.h
int count1bitsn(int n)
{
int count=0;
while(n)
{
count+=n1;
n=n1;
}
return count;
}
int main()
{
int n;
printf(Enter the value of n\n);
scanf(%d,n);
Hi,,
Think the No of 1 bits can be found in o(k) where k is the no of bits
set
while((n (n-1)) = 0)
{
c++;
n = n (n-1);
printf( n %d Cnt %d \n,n,c);
if(!n)
break;
}
printf(Cnt %d \n,c);
--~--~-~--~~~---~--~~
You
I have a simple method.
Let hash[x]=count of 1 bits in x for 0=x2^16
So for any 32-bit integer x, the count of 1 bits is hash[x0x]
+hash[x16].
We can pre-calculate all hash[] value.
On Mar 21, 1:24 pm, hijkl [EMAIL PROTECTED] wrote:
How to count the 1 bits in a integer?
int
The standard link
http://graphics.stanford.edu/~seander/bithacks.html
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com
To