Question: I am using inotify and want to efficiently check against the reported bitmask event (see [inotify man page](http://linux.die.net/man/7/inotify)).

Now I could brutely check against every bit on every event, but that would be extremely crude, if not stupid, as I would have N conditionals every time. Or is calling

```
( bitmask & mask ) == mask

```

for **each** mask already super efficient?

Since the resulting bitmask is basically just a well defined number, I should be able to use basic arithmetic operations for this. But before I think up something myself, I wanted to ask if there is a well-known, efficient way to check against a given bitmask. So, is there?

Answer: 
If there is only one bit set and if your code doesn't have to be portable, you can use intrinsics that give you the position of the set bit and then use the result in a switch statement. 
For gcc that would e.g. be 

```
__builtin_ffs

```
If it is necessary to check against every bit mask, there is no other way than to check explicitly. However, if the specific bit masks are known, bitwise checks could be done, effectively resulting in ruling out half of the possible bit masks in every step.