Welcome to the World of Binary Arithmetic!

Hello future Computer Scientists! This chapter, Binary Arithmetic, is the core foundation of how computers think and calculate. Everything a computer does—from running a game to processing a word document—boils down to incredibly fast addition, subtraction, multiplication, and division using only 0s and 1s.

Don't worry if this sounds intimidating! Binary arithmetic is actually simpler than decimal arithmetic because there are far fewer rules to remember. We will break down each operation step-by-step, making sure you feel confident dealing with 1s and 0s. Let's get calculating!

Why is Binary Arithmetic Important? (Context: Data Representation)

In the "Data Representation" section, we learned that all data (numbers, text, images) must be represented as binary digits (bits). If data is stored as bits, then any operation performed on that data must also use binary. The computer's Central Processing Unit (CPU) contains the Arithmetic Logic Unit (ALU), which is specifically designed to perform these binary calculations.


1. Binary Addition (The Foundation)

Binary addition is the most fundamental operation. If a computer can add, it can also subtract, multiply, and divide (by adapting the addition process).

The Four Golden Rules of Binary Addition

You only need to memorize four rules!

  • Rule 1: 0 + 0 = 0
  • Rule 2: 0 + 1 = 1
  • Rule 3: 1 + 0 = 1
  • Rule 4: 1 + 1 = 0 (and Carry 1)

The Tricky Rule Explained (Rule 4):
Think about the decimal system: when you add 5 + 5, you get 10. The 0 goes in the units column, and the 1 is carried over to the tens column.
In binary, 1 + 1 is two (2). Since we don't have a symbol for '2', we write it as 102. The 0 stays, and the 1 is carried over to the next column.

Extra Scenario (Triple 1s):

  • Rule 5: 1 + 1 + 1 = 1 (and Carry 1)
    (This happens when you have two digits plus a carry bit from the previous column. 1+1+1 equals three, which is written as 112.)
Step-by-Step Example: Adding 5 + 3 (0101 + 0011)

We start from the rightmost column (Least Significant Bit).

Numbers:
     0 1 0 1 (5)
+ 0 0 1 1 (3)
     -----

  1. Column 1 (Units): 1 + 1 = 0. Carry 1.
  2. Column 2 (Twos): 0 + 1 + (Carry 1) = 1 + 1 = 0. Carry 1.
  3. Column 3 (Fours): 1 + 0 + (Carry 1) = 1 + 1 = 0. Carry 1.
  4. Column 4 (Eights): 0 + 0 + (Carry 1) = 1. Carry 0 (no carry).

Result: 0 1 0 0 0 (This is 8 in decimal, which is correct!)

🚫 Common Mistake to Avoid: Overflow
If you are using a fixed number of bits (like 8 bits), and your answer requires a ninth bit (the final carry), this is called an overflow. The computer cannot store the full result, and the answer will be incorrect. This is a crucial concept in limited-storage systems.

2. Binary Subtraction (Borrowing)

Binary subtraction uses the concept of borrowing, which is very similar to how you learned to subtract in primary school.

The Basic Rules of Subtraction
  • Rule 1: 0 - 0 = 0
  • Rule 2: 1 - 1 = 0
  • Rule 3: 1 - 0 = 1
  • Rule 4 (The Borrow): 0 - 1 = 1 (and Borrow from the next column)

The Borrow Explained (Rule 4):
When you need to perform 0 - 1, you must look at the bit to the left (the next highest place value) and borrow 1 from it.

When you borrow 1 in binary, the value you bring back is 2 (or 102). So, 0 - 1 becomes 10 - 1, which equals 1.

Analogy: Imagine you need to subtract 1 apple, but you only have 0 apples. You borrow a bag of apples (worth 2 apples) from the person next door. You take 1 from the bag (leaving 1 apple), and the person next door now has one fewer bag.

Step-by-Step Example: Subtracting 5 - 3 (0101 - 0011)

Numbers:
     0 1 0 1 (5)
- 0 0 1 1 (3)
     -----

  1. Column 1 (Units): 1 - 1 = 0.
  2. Column 2 (Twos): 0 - 1. We cannot do this. We must borrow from Column 3.
    • Column 3 (Fours) changes from 1 to 0.
    • Column 2 changes from 0 to 102 (which is 2).
    • Calculation: 10 - 1 = 1.
  3. Column 3 (Fours): We borrowed 1, so the number is now 0. Calculation: 0 - 0 = 0.
  4. Column 4 (Eights): 0 - 0 = 0.

Result: 0 0 1 0 (This is 2 in decimal, which is correct!)

💡 Quick Review: Addition & Subtraction
  • Addition Key: Look for "1 + 1". The answer is 0 and Carry 1.
  • Subtraction Key: Look for "0 - 1". You must Borrow 1, making the 0 into 10 (or 2).

3. Binary Multiplication

Binary multiplication is the easiest operation of all! It uses the same 'shift and add' method as long multiplication in the decimal system, but the rules are much simpler because you are only multiplying by 0 or 1.

The Four Golden Rules of Multiplication
  • 0 x 0 = 0
  • 0 x 1 = 0
  • 1 x 0 = 0
  • 1 x 1 = 1

Did you notice? If there is even one 0, the answer is 0. If both are 1, the answer is 1. Super simple!

Step-by-Step Example: Multiplying 5 x 3 (0101 x 0011)

The process involves two steps: 1. Generate partial products. 2. Add them up.

Numbers:
          0 1 0 1 (Multiplicand: 5)
x      0 0 1 1 (Multiplier: 3)
          -----

  1. Multiply by the rightmost 1 (Units column of the Multiplier):
    1 x 0101 = 0101

    Partial Product 1: 0 1 0 1

  2. Multiply by the next 1 (Twos column of the Multiplier):
    1 x 0101 = 0101. We must shift this result one place to the left (by adding a 0 on the end).

    Partial Product 2: 0 1 0 1 0

  3. Multiply by the next 0s: (These result in all zeros, so we can ignore them, or add 00000 and 000000 for completeness).
  4. Add the Partial Products:

              0 1 0 1
    +      0 1 0 1 0
              -------
    (Remember your binary addition rules from Section 1!)
    Result: 0 1 1 1 1

Result: 011112 is 15 in decimal (8 + 4 + 2 + 1). Since 5 x 3 = 15, the calculation is correct!

🧠 Memory Trick: Shifting
Multiplying a binary number by 2 is the same as simply adding a 0 to the right end (a left shift).
Example: 0010 (2) becomes 0100 (4). This shifting is how computers perform multiplication quickly.

4. Binary Division

Binary division is typically performed by the computer using a method called repeated subtraction, but for manual calculation, we use the standard long division method, which is simpler in binary because there are only two choices: 0 or 1.

  • If the Divisor fits into the partial dividend, the quotient bit is 1.
  • If the Divisor does not fit, the quotient bit is 0.
Step-by-Step Example: Dividing 10 / 2 (1010 ÷ 10)

We are dividing 1010 (10) by 10 (2). The answer should be 5 (0101).

Divisor: 10     Dividend: 1 0 1 0

  1. Look at the first bit of the dividend: Is 10 (Divisor) smaller than 1? No. Quotient bit is 0.
  2. Look at the first two bits: Is 10 (Divisor) smaller than 10? No, they are equal.
    • Quotient bit is 1.
    • Subtract the divisor: 10 - 10 = 00.
  3. Bring down the next bit (1): We now have 01. Is 10 smaller than 01? No.
    • Quotient bit is 0.
    • We subtract 0: 01 - 00 = 01.
  4. Bring down the last bit (0): We now have 010. Is 10 smaller than 10? No, they are equal.
    • Quotient bit is 1.
    • Subtract the divisor: 10 - 10 = 00.

Quotient: 1 0 1 (The final answer is 0101, or 5 in decimal. Remainder is 0).

🔑 Key Takeaway: Efficiency
While we learn addition, subtraction, multiplication, and division, in reality, complex computer hardware often performs multiplication using rapid repeated addition, and division using rapid repeated subtraction and shifting. The simpler the operation, the faster the processor can work!

You have now mastered the basics of how a computer calculates! Keep practising these step-by-step methods, and binary arithmetic will soon become second nature.