This question may be more relevant in the Software Stack Package .
If you use an optimizing compiler, the likelihood that any form of n % <power of two>
will be optimized for n & <power of two minus one>
is anyway, since they are equivalent, but pretty much every architecture I'm talking about I can think is much more effective.
The first form expresses your intentions more clearly, although many developers recognize n & 1
as the "faster version" n % 2
.
source share