Add a bitCount() util function
This function returns the number of bits set in an unsigned integer.
This commit is contained in:
parent
fc56ac28fb
commit
cf62fe51dc
1 changed files with 16 additions and 0 deletions
16
utils.h
16
utils.h
|
@ -163,6 +163,22 @@ Qt::KeyboardModifiers x11ToQtKeyboardModifiers(int state);
|
|||
|
||||
void checkNonExistentClients();
|
||||
|
||||
static inline int bitCount(uint32_t mask)
|
||||
{
|
||||
#if defined(__GNUC__)
|
||||
return __builtin_popcount(mask);
|
||||
#else
|
||||
int count = 0;
|
||||
|
||||
while (mask) {
|
||||
count += (mask & 1);
|
||||
mask >>= 1;
|
||||
}
|
||||
|
||||
return count;
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// Must be outside namespace
|
||||
|
|
Loading…
Reference in a new issue