Modulo Calculator
Enter a and b to compute a mod b — supports arbitrarily large integers and both remainder conventions
Modulo Operation Explained
Modulo returns the remainder after division. For example, 17 mod 5 = 2 because 17 = 3 × 5 + 2.
Modulo Differences Across Languages
JavaScript/C++: The remainder sign matches the dividend. -13 % 7 = -6 (since -13 = -1 × 7 + (-6)).
Python/Math: The remainder is always non-negative. -13 % 7 = 1 (since -13 = -2 × 7 + 1).
This tool shows both styles, useful for competitive programming and cross-language development.
Real-world Applications
- Hash Functions: Modulo maps large keys to finite hash table slots
- Cryptography: RSA relies on modular exponentiation of large numbers
- Circular Arrays:
index % Nimplements ring buffers - Leap Year Check: year % 4 == 0 (simplified rule)
FAQ
What is 17 mod 5?
17 ÷ 5 = 3 remainder 2, so 17 mod 5 = 2. Verification: 3 × 5 + 2 = 17.
How does negative modulo work?
It varies by language: JavaScript returns -13 % 7 = -6 (sign of dividend), Python returns -13 % 7 = 1 (always non-negative). Python's convention aligns better with mathematical congruence classes.
How large can the numbers be?
Using JavaScript BigInt, this calculator supports integers of arbitrary precision — hundreds of digits long. It computes correctly regardless of size.
What are practical uses of modulo in programming?
Common uses: 1) hash table index mapping; 2) circular array indexing (index % N); 3) parity checks (n % 2); 4) pagination; 5) cryptographic algorithms (RSA etc.); 6) day-of-week calculations.