Explore how computers perform basic math using binary logic and the concept of carrying bits.
Have you ever wondered how a computer, which only understands 'on' and 'off,' can calculate complex physics or run massive video games? It all starts with a simple trick: carrying a single bit.
Binary addition works just like the decimal addition you learned in primary school, but it is much simpler because there are only two digits: and . There are four fundamental rules to memorize: 1. 2. 3. 4. (This is with a carry of to the next column).
Think of in binary as the number in decimal. Since we cannot write '2' in binary, we move to the next place value (the twos column), just like we move to the tens column when we hit in decimal.
Problem: Add (5) and (2).
$$\begin{array}{r@{\quad}l} & 101 \\ + & 010 \\ \hline \end{array}$$Result: (which is 7 in decimal).
Quick Check
What is the binary result of ?
Answer
When a column adds up to more than , we must carry the extra value to the left. This is exactly like adding in decimal; you write and carry the . In binary, if a column has three s (one from a previous carry and two from the numbers being added), the rule is: . You write in the current column and carry to the next. This simple mechanism allows computers to process massive numbers by chaining simple logic gates together.
Problem: Add (11) and (7).
1. Right column: , carry . 2. Second column: , carry . 3. Third column: , carry . 4. Fourth column: , carry . 5. Final carry: Bring down the last .
Result: (which is 18 in decimal).
Quick Check
In binary addition, what do you write down and what do you carry if a column sum equals 3 ()?
Answer
Write down 1 and carry 1 to the next column.
Computers store numbers in fixed-size containers called registers. A common size for beginners to study is 8-bit (one byte). But what happens if the result of your addition is 9 bits long? This is called an overflow error. The computer 'drops' the extra bit because it has no place to store it. This can lead to massive calculation errors, like a game character's health resetting to zero or a spacecraft's navigation system failing. Understanding the limits of your bit-width is crucial for stable programming.
Problem: In an 8-bit system, add (255) and (1).
1. Every column will result in , triggering a chain reaction of carries. 2. The mathematical sum is (a 9-bit number). 3. Since the system only holds 8 bits, the leftmost is discarded. 4. Result: .
Conclusion: An overflow error occurred because resulted in !
What is the binary sum of ?
Which of the following describes an overflow error?
In binary addition, results in writing a and carrying a .
Review Tomorrow
In 24 hours, try to write down the four basic rules of binary addition from memory and explain why .
Practice Activity
Try adding your age and a friend's age by first converting them to 8-bit binary numbers!