[LeetCode]Number of 1 bits

4ms C AC CODE..

 

int hammingWeight(uint32_t n) {
int i;
unsigned int t;
int c = 0;
for(i=0;i<31;i++){
t = (1<<i)^n;
if(t+(1<<i)==n){
c++;
}
}
if(n >= (1<<31)) c++;
return c;
}

posted @ 2015-07-02 14:16  hudiwei-hdw  阅读(120)  评论(0编辑  收藏  举报