Thursday, February 23, 2012

Modulous (Modulo) concept

What is Modulo2 of 3?
3/2 results Reminder 1. Thus Modulo2 of 3 is 1

What is Modulo4 of 3?
3 is less than 4. Thus Modulo4 of 3 is 3

What is Modulo4 of 13?
13/4 results Reminder 1. Thus Modulo4 of 12 is 1

There are numerous applications of this.

Let's say you want to do Clock programming where every 60 seconds results in 1 minute. You can use Modulo60 to reset your seconds' counter. If your seconds' counter reaches 61, Modulo60 of 61 will reset the seconds' counter to 1 and you can increase minutes' counter by 1. Similarly you can use Modulo24 to reset your hours' counter. If your hours' counter reaches 25, Modulo24 of 25 will reset the hours' counter to 1.

No comments:

Post a Comment