## G++中用于处理二进制位的built-in函数

G++中有一些很实用的内置函数，在解决一些与位运算有关的问题时特别有用。

int _builtin_ffs (unsigned int x)
Returns one plus the index of the least significant 1-bit of x, or if x is zero, returns zero.

_builtin_ffs(x)-1)==x&-x）

int __builtin_clz (unsigned int x) (即count left zero)
Returns the number of leading 0-bits in x, starting at the most significant bit position. If x is 0, the result is undefined.

int __builtin_ctz (unsigned int x)
Returns the number of trailing 0-bits in x, starting at the least significant bit position. If x is 0, the result is undefined.

int __builtin_popcount (unsigned int x)
Returns the number of 1-bits in x.

int __builtin_parity (unsigned int x)
Returns the parity of x, i.e. the number of 1-bits in x modulo 2.

int _builtin_ffsl (unsigned long)
Similar to __builtin
ffs, except the argument type is unsigned long.

int _builtin_clzl (unsigned long)
Similar to __builtin
clz, except the argument type is unsigned long.

int _builtin_ctzl (unsigned long)
Similar to __builtin
ctz, except the argument type is unsigned long.

int _builtin_popcountl (unsigned long)
Similar to __builtin
popcount, except the argument type is unsigned long.

int _builtin_parityl (unsigned long)
Similar to __builtin
parity, except the argument type is unsigned long.

int _builtin_ffsll (unsigned long long)
Similar to __builtin
ffs, except the argument type is unsigned long long.

int _builtin_clzll (unsigned long long)
Similar to __builtin
clz, except the argument type is unsigned long long.

int _builtin_ctzll (unsigned long long)
Similar to __builtin
ctz, except the argument type is unsigned long long.

int _builtin_popcountll (unsigned long long)
Similar to __builtin
popcount, except the argument type is unsigned long long.

int _builtin_parityll (unsigned long long)
Similar to __builtin
parity, except the argument type is unsigned long long.