Binary form of an integer number of 1s

 PS: integer not converted to binary form, the required number of binary integer form 1 of

#include <iostream>

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

  

Guess you like

Origin www.cnblogs.com/E-Dreamer-Blogs/p/12185542.html