3 ms·
Using gcc compiler intrinsics (which should compile to a single assembly instruction where possible): bool isPowerOf2(unsigned int n) { return __builtin_
by vilya 16y ago
Using gcc compiler intrinsics (which should compile to a single assembly instruction where possible):
bool isPowerOf2(unsigned int n) {
return __builtin_popcount(n) == 1;
}