__builtin_popcount()
是GCC提供的内建函数,主要作用是计算x表示成二进制时有多少个1(32位)。
例如:
int x = 7; // 7 = 111;
int n = __builtin_popcount(x); //n = 3;
类似于java中的Integer.bitcount()
函数,同样是计算二进制中1的个数。
__builtin_popcount()
是GCC提供的内建函数,主要作用是计算x表示成二进制时有多少个1(32位)。
例如:
int x = 7; // 7 = 111;
int n = __builtin_popcount(x); //n = 3;
类似于java中的Integer.bitcount()
函数,同样是计算二进制中1的个数。