leetcode 上的Counting Bits 总结

最近准备刷 leetcode  做到了一个关于位运算的题记下方法

int cunt = 0;

while(temp)

{

  temp = temp&(temp - 1);  //把二进制最左边那个1变为零

  count++;   //统计1的个数

}

同理把位二进制坐左边那个0变为1

就可以  temp = temp|(temp + 1)

原文地址:https://www.cnblogs.com/wenguang1996/p/5401944.html