Advertisement
Advertisement


How Does Modulus Divison Work


Question

I don't really understand how modulus division works. I was calculating 27 % 16 and wound up with 11 and I don't understand why.

I can't seem to find an explanation in layman's terms online. Can someone elaborate on a very high level as to what's going on here?

2014/08/21
1
106
8/21/2014 6:59:44 PM

Accepted Answer

The result of a modulo division is the remainder of an integer division of the given numbers.

That means:

27 / 16 = 1, remainder 11
=> 27 mod 16 = 11

Other examples:

30 / 3 = 10, remainder 0
=> 30 mod 3 = 0

35 / 3 = 11, remainder 2
=> 35 mod 3 = 2
2010/04/19
108
4/19/2010 5:53:45 AM


Maybe the example with an clock could help you understand the modulo.

A familiar use of modular arithmetic is its use in the 12-hour clock, in which the day is divided into two 12 hour periods.

Lets say we have currently this time: 15:00
But you could also say it is 3 pm

This is exactly what modulo does:

15 / 12 = 1, remainder 3

You find this example better explained on wikipedia: Wikipedia Modulo Article

2010/04/18

The simple formula for calculating modulus is :-

[Dividend-{(Dividend/Divisor)*Divisor}]

So, 27 % 16 :-

27- {(27/16)*16}

27-{1*16}

Answer= 11

Note:

All calculations are with integers. In case of a decimal quotient, the part after the decimal is to be ignored/truncated.

eg: 27/16= 1.6875 is to be taken as just 1 in the above mentioned formula. 0.6875 is ignored.

Compilers of computer languages treat an integer with decimal part the same way (by truncating after the decimal) as well

2013/06/11

The modulus operator takes a division statement and returns whatever is left over from that calculation, the "remaining" data, so to speak, such as 13 / 5 = 2. Which means, there is 3 left over, or remaining from that calculation. Why? because 2 * 5 = 10. Thus, 13 - 10 = 3.

The modulus operator does all that calculation for you, 13 % 5 = 3.

2016/06/29

modulus division is simply this : divide two numbers and return the remainder only

27 / 16 = 1 with 11 left over, therefore 27 % 16 = 11

ditto 43 / 16 = 2 with 11 left over so 43 % 16 = 11 too

2010/04/18

Very simple: a % b is defined as the remainder of the division of a by b.

See the wikipedia article for more examples.

2010/04/18

Source: https://stackoverflow.com/questions/2664301
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]