Exercise 5.1: Binary Arithmetic
Before we build circuits to add numbers for us, we need to understand how computers "think" about numbers. In this exercise, we will explore the binary number system and learn how to perform binary addition manually.
1) The Language of Computers
Computers don't use the decimal system (Base-10) like humans do. Instead, they use Binary (Base-2).
Why Binary?
Digital electronics work with switches (transistors) that have only two stable states:
- ON (High Voltage, 5V) \rightarrow Represents 1
- OFF (Low Voltage, 0V) \rightarrow Represents 0
Because there are only two symbols (0 and 1), counting works differently than we are used to.
Counting in Binary
In decimal, when we reach 9, we run out of digits, so we reset to 0 and carry a 1 to the next place (becoming 10). In binary, we run out of digits much faster!
- 0 is 0
- 1 is 1
- 2? We have no symbol for '2'. So we reset to 0 and carry a 1: 10
- 3 is 11
- 4? We reset both lower bits: 100
2) Binary Addition
Adding binary numbers is actually simpler than decimal addition because there are fewer rules to remember!
The Four Rules of Binary Addition
When adding two single bits:
- 0 + 0 = 0
- 0 + 1 = 1
- 1 + 0 = 1
- 1 + 1 = 10 (Write down 0, Carry 1)
Wait, what if we have a carry coming in?
- 1 + 1 + 1 = 11 (Write down 1, Carry 1)
Let's Try an Example
Let's add 6 (110) and 3 (011).
+ 0 1 1 (3)
-------
1 0 0 1 (9)
Step-by-Step:
- Rightmost column (1s place): 0 + 1 = 1. (Result: 1)
- Middle column (2s place): 1 + 1 = 10. Write down 0, carry the 1 to the next column. (Result: 01)
- Leftmost column (4s place): 1 + 0 + \text{carry}(1) = 10. Write down 0, carry the 1.
- Final Carry: Bring down the last carry.
- Final Result: 1001 (which is 8 + 1 = 9 in decimal).
3) Overflow
Sometimes, the result of an addition is too big to fit in the number of bits we have available.
Imagine we only have a 4-bit system (like a very old computer). The biggest number we can store is 1111 (Decimal 15).
If we try to calculate 1000 (8) + 1000 (8): Result: 10000 (16)
The result needs 5 bits, but we only have 4! The extra '1' on the left is lost or causes an error flag. This is called Overflow.
4) Practice
You are now ready to understand the hardware that does this for us! In the next exercise, you will build the Half Adder and Full Adder circuits that physically implement these addition rules.