Binary Modulo Calculator – Free

This binary modulo calculator divides the first binary number by the second and returns the remainder, shown in both binary and decimal.

How to use the Binary Modulo Calculator tool

  1. Type the number to be reduced into the First binary number box.
  2. Enter the modulus, the number you divide by, in the Second binary number box.
  3. Select Calculate remainder. The Example button runs 1011 mod 11.
  4. Read the remainder on the Binary and Decimal lines in the Result box.
  5. Select Copy to copy the remainder, or Clear to enter new values.

What the modulo operation returns

Modulo gives what is left over after whole-number division. For a dividend a and a divisor b, the quotient q and remainder r satisfy a = q × b + r, with r smaller in magnitude than b. The page example is 1011 mod 11, or 11 mod 3 in decimal. Three goes into eleven three times, leaving 2, so the result is Binary: 10 and Decimal: 2.

The quotient half of that identity comes from the Binary Division Calculator. Using both tools on the same inputs gives q = 11 and r = 10, and 11 × 11 + 10 = 1011 checks out: 3 × 3 + 2 = 11.

Modulo by a power of two keeps the low bits

When the divisor is a power of two, no division is needed. The remainder is the low bits of the dividend. Mod 10000, which is 16, keeps the last four bits. So 11011101 mod 10000 is 1101, or 221 mod 16 = 13. In code this is the familiar mask x & (n - 1), which works only when n is a power of two and x is not negative.

11011101 mod 10000

Binary: 1101
Decimal: 13

Negative operands: the remainder follows the dividend

Programming languages disagree about remainders of negative numbers. This binary modulo calculator uses truncated division, the rule in C, Java and JavaScript: the remainder has the same sign as the first operand. So -1011 mod 11 returns -10, which is -2, and 1011 mod -11 returns 10, which is 2.

Python and Ruby use floored division, where the remainder takes the sign of the divisor. Python evaluates -11 % 3 as 1, not -2. If you are checking code written in such a language and the divisor is positive, add the divisor to a negative result from this tool to get the floored value: -2 + 3 = 1.

Where binary modulo is used

Remainders are everywhere in low-level code. Note that CRC checksums use a different kind of remainder. A CRC divides polynomials with XOR and no carries, so its result will not match the integer remainder computed here.

  • Hash tables pick a bucket with hash mod table size.
  • Ring buffers wrap an index with index mod capacity.
  • Even or odd tests use mod 10 (two), which is the last bit.
  • Alignment checks use address mod 100 or mod 1000 to test 4-byte or 8-byte boundaries.

Input rules and special cases

Operands may be up to 4,096 characters each, with an optional 0b prefix and an optional leading minus sign. A zero in the second box returns The divisor must be nonzero. If the dividend is smaller than the divisor, the dividend itself is the remainder: 11 mod 1011 is 11. A remainder of zero, as in 1100 mod 11, means the first number is an exact multiple of the second. The arithmetic happens in your browser.

Frequently asked questions

How is modulo different from division?

Division returns how many times the divisor fits, and modulo returns what is left. For 1100100 and 111, which are 100 and 7, the Binary Division Calculator gives 1110 (14) and this tool gives 10 (2).

Why is my remainder negative?

The first operand was negative. The tool keeps the sign of the dividend, as C and JavaScript do. Languages with floored modulo, such as Python, would return a non-negative value for a positive divisor.

How do I compute a number mod 2, 4 or 8 quickly?

Keep the last one, two or three bits of the binary number. Those divisors are 10, 100 and 1000 in binary, and the remainder is whatever sits below the divisor's single 1 bit.

Can I use this for CRC or polynomial remainders?

No. This tool does ordinary integer arithmetic with carries and borrows. CRC algorithms divide over GF(2), where subtraction is XOR. Use the CRC32 Calculator on this site for checksums.

Related tools