How to count the number of trailing zeros of an integer? The simplest way is
to use the built-in function __builtin_ctz()
:
uint64_t count(uint64_t n) {
return __builtin_ctz(n);
}
What will happen if we don't have __builtin_ctz()
? If we have another
built-in function __popcount()
, which can …