Binary Arithmetic: Addition and Subtraction

Master binary addition and subtraction with carry and borrow operations. Step-by-step examples, overflow detection, and connection to how CPUs work.

Binary (Base 2)Binary (Base 2)Arithmetic

Detailed Explanation

Binary arithmetic follows the same rules as decimal arithmetic but with only two digits: 0 and 1. Understanding binary addition and subtraction is essential for grasping how CPUs perform calculations at the hardware level.

Binary addition rules:

  • 0 + 0 = 0
  • 0 + 1 = 1
  • 1 + 0 = 1
  • 1 + 1 = 10 (0 with a carry of 1)
  • 1 + 1 + 1 = 11 (1 with a carry of 1)

Example — adding 1011 + 0110:

  Carry: 1 1 1 0
         1 0 1 1
       + 0 1 1 0
       ---------
       1 0 0 0 1

Verification: 11 + 6 = 17, and 10001₂ = 17₁₀. Correct.

Binary subtraction with borrowing:

  • 0 - 0 = 0
  • 1 - 0 = 1
  • 1 - 1 = 0
  • 0 - 1 = 1 with a borrow of 1 from the next column

Example — subtracting 1100 - 0101:

  Borrow: 0 1 1 0
          1 1 0 0
        - 0 1 0 1
        ---------
          0 1 1 1

Verification: 12 - 5 = 7, and 0111₂ = 7₁₀. Correct.

Overflow detection:

In a fixed-width binary system (such as 8-bit), overflow occurs when the result exceeds the available bits. For unsigned 8-bit addition, overflow happens when the result is greater than 255. For signed numbers using two's complement, overflow occurs when adding two positive numbers yields a negative result, or vice versa. CPUs set special flags (carry flag, overflow flag) to indicate these conditions, which programmers can check using conditional branch instructions.

Binary multiplication uses the same shift-and-add technique as decimal long multiplication, making it a sequence of shifts and additions that CPU hardware implements efficiently.

Use Case

CPU designers and embedded systems programmers trace through binary addition to verify that arithmetic logic unit (ALU) designs correctly handle carry propagation and overflow.

Try It — Number Base Converter

Open full tool