剑指offer-二进制中1的个数

题目描述

输入一个整数,输出该数二进制表示中1的个数。其中负数用补码表示。
 1 class Solution {
 2 public:
 3      int  NumberOf1(int n) {
 4          int count =  0;
 5          while(n)
 6          {
 7              count ++;
 8              n = (n - 1) & n;
 9          }
10          return count;
11      }
12 };
原文地址:https://www.cnblogs.com/Jawen/p/10974674.html