1. __builtin_popcount(unsigned int n)
判斷 的二進制中有多少個
int n = 15; //二進制爲1111
cout<< __builtin_popcount(n) <<endl; //輸出4
2. __builtin_ffs(unsigned int n)
判斷 的二進制末尾最後一個 的位置
int n = 1; //1
int m = 8; //1000
cout<< __builtin_ffs(n) <<endl; //輸出1
cout<< __builtin_ffs(m) <<endl; //輸出4
3. __builtin_ctz(unsigned int n)
判斷 的二進制末尾後面 的個數
int n = 1; //1
int m = 8; //1000
cout<< __builtin_ctzll(n) <<endl; //輸出0
cout<< __builtin_ctz(m) <<endl; //輸出3
4. __builtin_clz(unsigned int n)
返回前導的 的個數
PS:那麼用此方法可以計算出第一個1的位置
int n = 1; //1
int m = 8; //1000
cout<< 32 - __builtin_clz(n) <<endl; //輸出1
cout<< 64 - __builtin_clzll(m) <<endl; //輸出4
5. __builtin_parity(unsigned int n)
判斷 的二進制中 的個數的奇偶性
int n = 15; //二進制爲1111
int m = 7; //111
cout<< __builtin_parity(n) <<endl; //偶數個,輸出0
cout<< __builtin_parity(m) <<endl; //奇數個,輸出1