Toolstia / Modulo calculator
Modulo calculator
The modulo operation gives the remainder after dividing one whole number by another. Enter a dividend and a divisor to get a mod n, the quotient and the full division sentence. For negative numbers, the tool shows the three different conventions used in maths and programming.
Enter two whole numbers. Negative numbers are allowed.
For positive numbers all three results agree. They differ when a number is negative, which is why the same expression can give different answers in different programming languages.
How it works
- Enter the dividend and the divisor.
- Read a mod n, the quotient and the division.
- Compare the conventions if a number is negative.
The basic idea
17 mod 5 is 2, because 17 = 5 × 3 + 2. The result is how much is left after taking out as many whole copies of the divisor as fit.
Negative numbers
Languages disagree. JavaScript, C and Java give -2 for -17 % 5 (the sign follows the dividend). Python gives 3 (the sign follows the divisor). Mathematicians usually want a result from 0 up to n − 1, which is 3 here.
Uses
Modulo tells you whether a number is even or odd, wraps clock hours around (15 mod 12 = 3), cycles through a list, and underlies checksums and encryption.
Exact big numbers
Whole numbers of any size are handled exactly, not rounded.
Questions
What is 0 mod n?
It is 0 for any non-zero n.
Can the divisor be negative?
Yes. The conventions are shown separately so you can pick the one your language uses.
Is anything uploaded?
No. Your numbers stays in your browser and is never sent anywhere.