This is for the "wrap". Assuming width and height are powers of two (otherwise it won't work, so it's better to be true), x & (width - 1) is basically equivalent to x % width , except that it also works for negative x (whereas x % width with negative x will have a negative result) and almost certainly faster.
Or to visually display an example, for example width = 64 and x = 64+12 = 76 , then
x = 00000000 00000000 00000000 01001100 w = 00000000 00000000 00000000 01000000 w-1 = 00000000 00000000 00000000 00111111 x & w-1 = 00000000 00000000 00000000 00001100 = 12
As you can see from form w-1 , the operation x & w-1 is similar to executing only the lower bits of x , assuming, of course, that w is still a power of two. Thus, bits with weights 64 and multiples of 64 are deleted in the same way as the true βmodulo 64β operation (which is not % in C #, if you work with integer signs, this is the remainder).
source share