C++ popcount()含义

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);
  }
}
发布了766 篇原创文章 · 获赞 474 · 访问量 254万+

猜你喜欢

转载自blog.csdn.net/u010164190/article/details/105496756