Welcome to Binary Arithmetic!
Ever wondered how a computer actually "thinks" when it's doing math? Since computers are made of tiny switches that can only be ON (1) or OFF (0), they can't use the numbers 0-9 like we do. Instead, they use binary arithmetic.
In this chapter, we are going to learn the two main ways computers handle numbers: adding them together and shifting them to multiply or divide. Don't worry if it seems a bit strange at first—once you learn the four simple rules of addition, you'll be a binary pro!
1. Adding Binary Numbers
Binary addition works exactly like the "column addition" you learned in primary school, but it’s actually simpler because there are fewer numbers to remember. In our decimal system (Base 10), we carry over when we hit ten. In binary (Base 2), we carry over when we hit two!
The Four Golden Rules
To add any binary numbers, you just need to memorize these four outcomes:
1. \(0 + 0 = 0\)
2. \(0 + 1 = 1\)
3. \(1 + 1 = 0\) (carry 1 to the next column)
4. \(1 + 1 + 1 = 1\) (carry 1 to the next column)
Step-by-Step: Adding Two Numbers
Let's add \(00101011\) (43) and \(00010110\) (22).
Step 1: Start from the right-hand side (the Least Significant Bit).
Step 2: Apply the rules column by column.
Step 3: If you have a 1 and a 1, put a 0 down and "carry" the 1 over to the left neighbor.
Quick Review: Why do we carry? Just like in \(7 + 5 = 12\), you write the 2 and carry the 1. In binary, \(1 + 1\) is "two," which is written as \(10\). So, we write the \(0\) and carry the \(1\).
Adding Three Numbers
Your syllabus says you might need to add up to three binary numbers at once. The rules stay the same!
Example: If a column has three 1s (\(1 + 1 + 1\)), the total is "three." In binary, three is written as \(11\).
So, you write down a 1 and carry a 1.
Common Mistake: The "Overflow"
In your exam, the answer will be a maximum of 8 bits long. You won't be expected to carry a number into a 9th bit. If you find yourself with an extra "carry" at the very end of an 8-bit sum, double-check your math!
Key Takeaway: Binary addition is just column addition with carrying. Remember that \(1+1\) is \(0\) carry \(1\), and \(1+1+1\) is \(1\) carry \(1\).
2. Binary Shifts
Binary shifts are a super-fast way for a computer to perform multiplication and division. Instead of doing complex math, the computer just slides the bits to the left or the right.
Logical Left Shift (Multiplication)
When you shift bits to the left, the number gets bigger.
- Shifting 1 place left multiplies the number by \(2\).
- Shifting 2 places left multiplies the number by \(4\) (\(2 \times 2\)).
- Shifting 3 places left multiplies the number by \(8\) (\(2 \times 2 \times 2\)).
How to do it:
1. Move every bit to the left by the number of places requested.
2. Fill the empty gaps on the right with 0s.
3. Any bits that "fall off" the left side are simply discarded.
Logical Right Shift (Division)
When you shift bits to the right, the number gets smaller.
- Shifting 1 place right divides the number by \(2\).
- Shifting 2 places right divides the number by \(4\).
How to do it:
1. Move every bit to the right.
2. Fill the empty gaps on the left with 0s.
3. Any bits that "fall off" the right side are gone forever!
Real-World Analogy
Imagine the number \(500\). If you shift all digits one place to the left and add a \(0\), it becomes \(5000\) (multiplied by 10). Binary shifts do the exact same thing, but because it's Base 2, it multiplies or divides by powers of 2.
Did you know? Shifting is much "cheaper" for a computer's processor than actual multiplication. It takes less energy and time to just slide bits around!
Quick Guide to Powers of 2
If the exam asks you to multiply or divide using shifts, use this checklist:
- \(2^1 = 2\) (Shift 1 place)
- \(2^2 = 4\) (Shift 2 places)
- \(2^3 = 8\) (Shift 3 places)
- \(2^4 = 16\) (Shift 4 places)
Key Takeaway: Left shift = Multiply. Right shift = Divide. Always fill the new empty spaces with 0s.
Summary Checklist
Before you move on, make sure you can:
- Add two 8-bit binary numbers together.
- Add three 8-bit binary numbers together.
- Use a Left Shift to multiply a number by 2, 4, or 8.
- Use a Right Shift to divide a number by 2, 4, or 8.
- Explain that shifts are used for simple multiplication and division by powers of 2.
Top Tip for the Exam: Always double-check your binary addition by converting the numbers to decimal, adding them normally, and then seeing if your binary answer matches!