1.定义
std::popcount
定义于头文件 <bit>
template<class T>
constexpr int popcount(T x) noexcept;(C++20起加入)
返回值:返回1的位的个数.
2.Demo
include <iostream>
using namespace std;
int dd;
int main(){
for(int i = 0 ;i < 100;i++){
dd = __builtin_popcount(i);
printf("i = %d, popcount = %d\n", i ,dd);
}
}
C++ popcount()含义
猜你喜欢
转载自blog.csdn.net/u010164190/article/details/105496756
今日推荐
周排行