π Lesson: Binary Arithmetic with 2βs Complement
π― Learning Objectives
By the end of this lesson, students will be able to:
- Explain how 2βs complement represents signed binary numbers.
- Convert between binary and decimal using 2βs complement.
- Perform binary addition and subtraction using 2βs complement.
- Detect and interpret overflow and carry conditions
1οΈβ£ Review: What Is 2βs Complement
Key Concepts
- 1βs Complement: Flip all bits (0 β 1, 1 β 0).
- 2βs Complement: Take the 1βs complement and add 1.
- Used to represent negative numbers in binary systems.
Range in 8-bit:
Range in 8-bit
| Type | Binary Range | Decimal Range |
|---|---|---|
| Positive | 00000001 to 01111111 |
+1 to +127 |
| Zero | 00000000 |
0 |
| Negative | 11111111 to 10000000 |
-1 to -128 |
2οΈβ£ Binary Addition Using 2βs Complement
Method
- Add the binary numbers directly.
- Ignore the carry out of the MSB.
- Check for overflow: occurs when the result sign is incorrect.
Example:
-
Add +25 and -12
+25 β 00011001
-12 β 11110100 (2βs complement of 00001100)
Sum β 00001101 β +13 β
Overflow Example:
-
Add +100 and +50
+100 β 01100100
+50 β 00110010
Sum β 10010110 β -106 β Overflow!
3οΈβ£ Binary Subtraction Using 2βs Complement
Method
- Convert the subtrahend to its 2βs complement.
- Add it to the minuend.
Example:
-
Subtract 25 - 12
25 β 00011001
12 β 00001100 β 2βs complement β 11110100
Sum β 00001101 β +13 β
-
Subtract 12 - 25
12 β 00001100
25 β 00011001 β 2βs complement β 11100111
Sum β 11110011 β -13 β
4οΈβ£ Overflow vs Carry
| Condition | Meaning in 2βs Complement |
|---|---|
| Carry | Can be ignored in most cases |
| Overflow | Indicates result is out of range |
Overflow Detection
- Happens when adding two numbers with the same sign yields a result with a different sign.
5οΈβ£ Practice Exercises
-
Addition
01101001+1101001011111110+0101010100110101+01110010 -
Subtraction (using 2βs complement)
01101001-1101001011111110-0101010100000010-10101010
Make sure you:
- Show all steps.
- Indicate if thereβs a carry or overflow.
- Convert results to decimal for verification.
6οΈβ£ Shortcut for 2βs Complement Conversion
Quick Method:
-
Start from the LSB.
-
Copy bits up to the first 1.
-
Invert all remaining bits.
Example:
Original: 00001100
2βs Complement: 11110100
7οΈβ£ Wrap-Up Discussion
- Why is 2βs complement preferred in digital systems?
- How does overflow differ from carry?
- What happens when subtraction results in a number outside the representable range?