Binary Arithmetic Rules and Formulas

Understanding Binary Arithmetic

Binary arithmetic is the foundation of all digital computing. It follows the same principles as decimal arithmetic but uses only two digits: 0 and 1. This article explains the core formulas and rules for binary addition, subtraction, multiplication, division, and bitwise operations. For a broader introduction, see our guide on What is Binary Arithmetic?.

Binary Addition

Binary addition is performed bit by bit, starting from the least significant bit (rightmost). The basic rules are:

  • 0 + 0 = 0
  • 0 + 1 = 1
  • 1 + 0 = 1
  • 1 + 1 = 0 (carry 1 to the next higher bit)
  • 1 + 1 + 1 = 1 (carry 1)

The carry propagates to the left. For example, adding 1011 (11 in decimal) and 0111 (7) yields 10010 (18). The formula for the sum bit at position i is:

Si = (Ai XOR Bi) XOR Ci

where Ai and Bi are the input bits, and Ci is the carry-in from the previous lower bit. The carry-out to the next higher bit is:

Ci+1 = (Ai AND Bi) OR (Ai AND Ci) OR (Bi AND Ci)

This is the classic full adder circuit used in all modern processors.

Why Carrying Works

In base 2, when the sum of two bits exceeds 1 (i.e., 2 in decimal), we need to represent that as a '0' with a carry of '1' to the next place. Each bit position represents a power of 2. A carry effectively adds twice the value of the current position, which matches the next higher position. This is analogous to decimal addition where 9+1 gives 0 with a carry of 1.

Binary Subtraction

Subtraction can be done directly using borrowing or more efficiently using two’s complement. The direct rules:

  • 0 - 0 = 0
  • 1 - 0 = 1
  • 1 - 1 = 0
  • 0 - 1 = 1 (borrow 1 from the next higher bit)

When borrowing, the borrowed bit becomes 2 in the current column. For instance, subtracting 0111 from 1010 (10 – 7) gives 0011 (3). The formula using two’s complement is simpler: A - B = A + (~B + 1). This method is used in computers because it avoids separate subtraction hardware. See our step-by-step guide for more examples.

Binary Multiplication

Binary multiplication follows the same pattern as decimal: multiply the multiplicand by each bit of the multiplier (which is either 0 or 1) and then add the shifted results. The formula for multiplying n-bit numbers X and Y is:

P = ∑i=0m-1 (X · yi · 2i)

where yi is the i-th bit of Y (0 or 1). Since multiplying by a power of 2 simply shifts left, binary multiplication is essentially shift-and-add. The product of two n-bit numbers requires up to 2n bits. For example, 101 (5) × 011 (3) = 01111 (15).

Binary Division

Division is performed by repeated subtraction, similar to long division in decimal. The algorithm:

  1. Compare the dividend (or remainder) with the divisor.
  2. If the dividend is larger, subtract the divisor and write a 1 in the quotient; otherwise write 0.
  3. Bring down the next bit and repeat.

For example, dividing 1001 (9) by 0010 (2):

  • First 4 bits: 1001 ≥ 0010? Yes → quotient 1, remainder 1001 – 0010 = 0111.
  • Bring down next bit (none), final quotient 0100 (4), remainder 0001 (1).

The formula is iterative: Rk+1 = Rk – D if Rk ≥ D, else Rk+1 = Rk. Division by zero is undefined and causes overflow.

Bitwise Operations

Bitwise operations work on individual bits and are fundamental in programming. They treat binary numbers as sets of bits.

AND (&)

A & B returns 1 only if both bits are 1. Formula: Ri = Ai · Bi (Boolean product). Used to mask bits.

OR (|)

A | B returns 1 if at least one bit is 1. Formula: Ri = Ai + Bi – Ai·Bi (Boolean sum). Used to set bits.

XOR (^)

A ^ B returns 1 if bits differ. Formula: Ri = Ai ⊕ Bi. Used in parity checks and encryption.

NOT (~)

~A inverts all bits. Formula: Ri = 1 – Ai. In two’s complement, ~A = -A - 1.

Left Shift (<<) and Right Shift (>>)

Left shift by n bits multiplies by 2n: A << n = A × 2n. Right shift divides by 2n (rounding down for unsigned).

For a programmer’s perspective, see Binary Calculations for Programmers.

Historical Origin

The binary system was first described by Gottfried Wilhelm Leibniz in 1703. He saw the parallels between binary numbers and the I Ching. George Boole later developed Boolean algebra in the 1850s, which became the basis for bitwise operations. Claude Shannon applied Boolean algebra to relay circuits in 1937, birthing digital logic. Today, binary arithmetic is the lifeblood of every computer processor.

Practical Implications

Binary arithmetic enables all digital computation. Addition is performed by millions of full adders in CPUs. Subtraction uses two’s complement, eliminating dedicated hardware. Multiplication and division are implemented via shifters and adders. Bitwise operations are key in low-level programming, networking, and cryptography.

Edge Cases and Overflow

  • Overflow: When the result exceeds the representable range. For unsigned numbers, overflow occurs when there is a carry out of the most significant bit. For signed numbers, overflow occurs when the sign bit changes unexpectedly.
  • Division by zero: Undefined; CPUs raise an exception.
  • Signed vs. unsigned: The same bit pattern can represent different values. For example, 1111 as unsigned is 15, but as 4-bit signed is –1. Our interpretation guides explain this in detail.

Understanding these rules helps in debugging and optimizing code. For common questions, check the Binary Calculator FAQ.

Try the free Binary Calculator ⬆

Get your Binary arithmetic operations including addition, subtraction, multiplication, division, and bitwise operations. result instantly — no signup, no clutter.

Open the Binary Calculator

Contact Us