E-Dreamer

脚踏实地,仰望星空

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

 PS: 不将整数转化为二进制形态,求该整数的二进制形式中1的个数

#include <iostream>

class Count_1_num {
public:
	int count(int n) {
		int res = 0;
		while (n) {
			n = n & (n - 1);
			res++;
		}
		return res;
	}
};

  

posted on 2020-01-13 08:19  E-Dreamer  阅读(227)  评论(0编辑  收藏  举报