quote: Original post by qbvet
Yup, that''s why we subtract one, from 128 in this case.
128-1 = 127 (01111111) which is the bitmask used for
anding. But if you mean something like this: x % 129, we
have a problem due to the fact that 129 isn''t a power of two.
So when trying to use x & (129-1) instead of x % 129 we''ll
get a bad result because the mask, 128 (10000000) will just
deliver 128, or 0 -just like you said, Selkrank- when using the bitwise and-operator on x, and the mask. So if you are going to
use x & (y - 1) instead of x % y, you have to make sure
that y is a power of 2.. x & (2^z - 1).
Oh, of course. So, it''s fine when your range is a power of two. Hmm...
-Jussi