bit count in array
- by davit-datuashvili
hello i have following question i know that to count number of set bit in number of number of 1 bit there is following code
int t ;//in which we want count how many bit are set for instance 3 011 there is 2 bit set
int count=0;
while(t>0){
t&=(t-1);
count++;
}
now let take array example
int x[]={3,5,6,8,9,7};
i have following code
int sum=0;
int count;
for (int i=0;i<x.length;i++){
count=0;
while (x[i]>0){
x[i]&=(x[i]-1);
count++;
}
sum+=count;
}
I have question what is wrong? it doesn't work
doesn't show me result;