COA Notes
Binary addition, subtraction, multiplication, and division with step-by-step examples.
Introduction
Just like you learned to add and subtract decimal numbers in elementary school, computers perform arithmetic in binary. The rules are simpler — there are only two digits! — but the same principles of carrying and borrowing apply. Understanding binary arithmetic is crucial because this is literally what happens inside your CPU's ALU every nanosecond.
Binary Addition
Binary addition follows four basic rules:
And one extended rule: 1 + 1 + 1 = 11 (1 with carry 1)
Example: Adding 1011 + 1101
Step-by-step:
- Rightmost column: 1+1=10 → write 0, carry 1
- Next column: 1+0+1=10 → write 0, carry 1
- Next column: 1+1+1=11 → write 1, carry 1
- Leftmost column: 1+1+0=10 → write 0, carry 1
- Final carry: write 1
Overflow
If we're working with a fixed number of bits (say 4 bits), and the result needs 5 bits, we have an overflow. This is important in computer hardware where registers have fixed widths.
Binary Subtraction
Binary subtraction rules:
Example: Subtracting 1101 - 1010
Step-by-step:
- Rightmost: 1-0=1
- Next: 0-1 → borrow needed → 10-1=1, borrow from next position
- Next: 1(became 0 due to borrow)-0=0
- Leftmost: 1-1=0
Using Complements for Subtraction
In practice, computers don't subtract directly. Instead, they use the two's complement method: to compute A-B, they calculate A+(-B), where -B is the two's complement of B. This means the hardware only needs an adder, not a separate subtractor!
Binary Multiplication
Binary multiplication is simpler than decimal multiplication because you only multiply by 0 or 1:
The algorithm is: shift and add (just like decimal long multiplication).
Example: Multiplying 1101 × 1010
Key insight: For each bit of the multiplier:
- If the bit is 0, add nothing (write zeros)
- If the bit is 1, add the multiplicand shifted to the appropriate position
Hardware Implementation
In a CPU, multiplication is implemented using shift-and-add circuits. The multiplicand is shifted left (or the partial product is shifted right), and additions happen when the current multiplier bit is 1.
Binary Division
Binary division works like long division in decimal:
Example: Dividing 1101 ÷ 10
Result: 1101₂ ÷ 10₂ = 110₂ remainder 1₂ (13÷2 = 6 remainder 1) ✓
Division Algorithm
- Compare the divisor with the current portion of the dividend
- If the divisor fits (is ≤), write 1 in the quotient and subtract
- If the divisor doesn't fit (is >), write 0 in the quotient
- Bring down the next bit and repeat
Arithmetic with Signed Numbers
When working with signed binary numbers (using two's complement):
Addition of Signed Numbers
Just add normally — two's complement handles the sign automatically!
Example: 5 + (-3) in 4-bit two's complement
Detecting Overflow in Signed Addition
Overflow occurs when:
- Adding two positive numbers gives a negative result, OR
- Adding two negative numbers gives a positive result
Rule: Overflow occurs when the carry INTO the sign bit differs from the carry OUT of the sign bit.
Practical Significance
In Hardware Design
The ALU in every processor contains binary adder circuits. The most basic is the ripple-carry adder, where carry propagates bit by bit. Faster designs like carry-lookahead adders compute carries in parallel.
In Programming
Understanding binary arithmetic helps you:
- Debug bit manipulation code
- Understand integer overflow bugs
- Optimize code using bit shifts instead of multiplication
- Work with fixed-point arithmetic in embedded systems
Shift Operations as Arithmetic
- Left shift by 1 = multiply by 2 (1010 → 10100)
- Right shift by 1 = divide by 2 (1010 → 0101)
This is much faster than actual multiplication/division in hardware.
Key Takeaways
- Binary addition: only four rules, with carry propagation like decimal
- Binary subtraction in hardware uses two's complement addition (A-B = A+complement(B))
- Binary multiplication uses the shift-and-add method
- Binary division uses repeated subtraction (compare and subtract)
- Two's complement allows signed arithmetic with the same adder hardware
- Overflow detection is critical in fixed-width computations
- Shift operations provide fast multiplication/division by powers of 2
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Binary Arithmetic — Computer Organization & Architecture.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Computer Organization & Architecture topic.
Search Terms
computer-organization, computer organization & architecture, computer, organization, data, representation, binary, arithmetic
Related Computer Organization & Architecture Topics