๐งฎ Binary Complement Arithmetic
This module explores how 1โs complement and 2โs complement systems handle addition, subtraction, and multiplication in binary. These systems allow negative numbers to be encoded and manipulated using only addition and bitwise logic.
๐ 1. Complement Basics
| Type | Definition | Operation |
|---|---|---|
| 1โs Complement | Flip all bits | ~A (bitwise NOT) |
| 2โs Complement | Flip all bits, then add 1 | ~A + 1 |
โ 2. Addition in Complement Systems
โ 2โs Complement Addition
A = 0101 (5)
B = 1110 (-2 in 2's complement)
------------------
A + B = 0011 (3)- No special handling needed.
- Overflow is ignored unless sign bit flips unexpectedly.
โ 1โs Complement Addition (with end-around carry)
A = 0101 (5)
B = 1101 (-2 in 1's complement)
------------------
Sum = 10010 โ drop overflow bit โ 0010
Add carry: 0010 + 1 = 0011 (3)Overflow is ignored because we specifically designed complements to ignore overflow, it is by design, check Derivation of Complement Forms
to understand why it was designed like so
Overflow is ignored because we
specifically designed complements to ignore overflow, it is by design, check Derivation of Complement Forms
to understand why it was designed like soโ 3. Subtraction via Complement Addition
โ 2โs Complement Subtraction
To compute A - B, do A + (2โs complement of B):
A = 0101 (5)
B = 0011 (3)
~B + 1 = 1100 + 1 = 1101 (-3)
------------------
A - B = 0101 + 1101 = 10010 โ drop overflow โ 0010 (2)โ 1โs Complement Subtraction
Use A + (1โs complement of B) + 1, then apply end-around carry:
A = 0101 (5)
B = 0011 (3)
~B = 1100
------------------
Sum = 0101 + 1100 + 1 = 10010 โ drop overflow โ 0010
Add carry: 0010 + 1 = 0011 (2)โ๏ธ 4. Multiplication in Complement Systems
Multiplication is typically done using unsigned logic, then sign is handled separately.
โ Example: 2โs Complement Multiplication
A = 1110 (-2)
B = 0011 (3)
------------------
Unsigned: 2 ร 3 = 6
Sign: Negative ร Positive = Negative
Result: 11111010 (โ6 in 8-bit 2โs complement)โ ๏ธ Notes
- Multiplication requires sign extension.
- Most systems use Boothโs algorithm or signed multiplication logic.
๐งฉ Summary Table
| Operation | 1โs Complement | 2โs Complement |
|---|---|---|
| Addition | Add + end-around carry | Add directly |
| Subtraction | Add 1โs complement + 1 + carry | Add 2โs complement |
| Multiplication | Unsigned ร Unsigned, then apply sign | Same, with sign logic |
Last updated on