- How does mod of power of 2 work on only lower order bits of a binary number (
1011000111011010)? - What is this number mod 2 to power 0, 2 to power 4?
- What does power of 2 have to do with the modulo operator? Does it hold a special property?
- Can someone give me an example?
The instructor says “When you take something mod to power of 2 you just take its lower order bits”. I was too afraid to ask what he meant =)
He meant that taking
number mod 2^nis equivalent to stripping off all but thenlowest-order (right-most) bits ofnumber.For example, if n == 2,
So in other words,
number mod 4is the same asnumber & 00000011(where&means bitwise-and)Note that this works exactly the same in base-10:
number mod 10gives you the last digit of the number in base-10,number mod 100gives you the last two digits, etc.