He meant that taking number mod 2^n
is equivalent to stripping off all but the n
lowest-order (right-most) bits of number
.
For example, if n == 2,
number number mod 4
00000001 00000001
00000010 00000010
00000011 00000011
00000100 00000000
00000101 00000001
00000110 00000010
00000111 00000011
00001000 00000000
00001001 00000001
etc.
So in other words, number mod 4
is the same as number & 00000011
(where &
means bitwise-and)
Note that this works exactly the same in base-10: number mod 10
gives you the last digit of the number in base-10, number mod 100
gives you the last two digits, etc.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…