Pages

Wednesday, January 25, 2012

Doesn't Everyone Knows Modulus Division? Yeah, Right!

Modulus Division Introduction

   Have you ever heard or seen modular division before? Modulus division often involves the % symbol as the operator just like + for addition, - for subtractions, * for multiplication, and / for division. It is a lot easier than long division because normally it is used in simple applications like figuring out if a number is even or odd. If I asked a programmer how to determine if an integer (-9,-8...0,1,2...9,10) was even he would answer "number percent sign 2 is equal to 0" or sometimes "use modular division". Modulus Division + Common Operation Calculator
   

Definition of "Modulus Division"
Many of the definitions on the internet for Modulus Division seem hellishly unreasonable, so let me put it in simple terms.
In simple terms, modulus division is the process of dividing one number by another (division) only to find the remainder that is left over. The number of times the number goes into the other is thrown away (hypothetically). All modulus division does is return the remainder.



Common Mathematical Examples
2 % 6 = 2
6 is bigger than 2 to start with so the remaining integer of the dividend is 2.

6 % 3 = 0
6 / 3 = 2 with a remainder of 0.

5 % 2 = 1
5/2 is 2.5 which is not an integer, so, you need to find the highest number that does fit into 5 that is a multiple of 2 (hint: it rhymes with s'more). Four and... 5 - 4 = 1.

16 % 16 = 0
16 goes into 16 one time only and has a remainder of 0.

1000 % 3 = 1
999 is a multiple of 3 that is less than the dividend, 1000. Thus, 1000 - 999 = 1.


How to do Modulus Division
An example of long division.
16 % 15 = 1
To solve a modulus division problem, you need to know the 3 key terminologies that go along with regular division: the quotient, dividend, and divisor. So, when prompted with a modulus division question you need to go back to the long division days where the first thing you do is think of the largest multiple of the divisor that is smaller than the dividend and then subtract that multiple times the divisor to find the remainder. If the quotient is greater than your divisor, then you did not use the highest integer for your multiple of the divisor.



Importance Of Modulus Division
In computer programming it can be used to distinguish whether an array or list of variables is of an appropriate size for a system. An example of that is if a system could only interpret bytes as arrays of 8 bits, the system could use modulus division to be sure no sets of the array would be broken into a piece of less than 8 pieces. {A byte is a unit of data storage used in digital systems and computers with 8 individual bits (binary digits)}.

Another example in computer science is to determine whether a number is even, odd, or even prime. The prime number algorithm takes a bit more thought than the even and odd number algorithm, so I will just show an example of an even number algorithm in the following section titled "Example Code Snippets."

Example Code Snippets
[in Java] 
//Even number method
public void getEven(int num){
if(num%2==0){
return true;
} else {
return false;
}

More Resources

No comments:

Post a Comment