Friday 23 December 2016

Modulus operator


The way modulo arithmetic works is like a clock. It takes a number and map it to the range based on the remainder when you divide that number.

Lets go through an example to make the point clear.

14%10
If you think go a 10 hour clock, to evaluate 14%10, start from 0 and make 14 steps the destination will be same as the remainder we would get by dividing 14 by 10.





The modulo operator is so powerful in algorithm. One of the example of modulo operator in algorithm is to simulate an infinite array.



No comments:

Post a Comment