mod2k

fnBigInt mod2k(BigInt n, size_t k) pure @safe

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

nThe value to reduce
kThe power of 2 for the modulus

Returns

n mod 2^k (always non-negative)