mod2k
Computes n mod 2^k (reduction modulo a power of 2).
Efficiently masks the lower k bits of the number. Handles negative numbers correctly by computing the proper positive remainder.
Parameters
n | The value to reduce |
k | The power of 2 for the modulus |
Returns
n mod 2^k (always non-negative)