Digital Electronics
Complements; Codes; Signed Number Representations
C-CAT
Complements
Complements simplify subtraction and represent negative numbers.
6.1 1's Complement (Binary)
Flip every bit (0→1, 1→0).
- +5 = 00101 → -5 (5-bit) = 11010
- Used in older systems; has two representations of zero
6.2 2's Complement (Binary)
1's complement + 1 (add 1 to LSB).
- Most widely used in modern computers
- Unique zero representation
- Range for n bits: -2^(n-1) to +2^(n-1)-1
Example: -5 in 8-bit 2's complement:
- +5 = 00000101
- 1's comp = 11111010
- +1 → 11111011
6.3 9's Complement (Decimal)
Subtract each digit from 9.
Used for decimal subtraction: (A - B) = A + 9's_comp(B) + 1 (end-around carry)
Example: 52520 - 38380 using 9's complement:
- 9's comp of 52520 (5 digits) = 99999 - 52520 = 47479
- Add with end-around carry to get result
6.4 10's Complement (Decimal)
9's complement + 1
Codes
7.1 Weighted vs Non-Weighted Codes
| Type | Definition | Example |
|---|---|---|
| Weighted | Each bit has fixed weight | BCD (8421) |
| Non-weighted | No positional weights | Gray, Excess-3 |
7.2 BCD (Binary Coded Decimal)
- Each decimal digit → 4-bit binary
- Weights: 8, 4, 2, 1
- Valid BCD: 0000 to 1001 only (0–9)
- Invalid: 1010–1111 (used for other codes)
Example: (254)₁₀ → BCD
| 2 | 5 | 4 |
|---|---|---|
| 0010 | 0101 | 0100 |
BCD → Decimal: Group in 4-bit nibbles: (0010 0101 0100) → 254
BCD → Binary: First convert BCD to decimal, then decimal to binary.
7.3 Excess-3 Code (XS-3)
- Non-weighted code
- Each BCD code + 0011 (3)
- Used for BCD addition (avoids invalid states during carry)
Conversion:
- Decimal → BCD → Add 3 to each digit
- Excess-3 → Subtract 3 from each nibble → BCD → Decimal
Example: (5)₁₀ → 0101 (BCD) → 0101 + 0011 = 1000 (Excess-3)
7.4 Gray Code
- Non-weighted, not arithmetic
- Only one bit changes between consecutive values
- Used in: shaft encoders, K-maps, error reduction in transitions
| Decimal | Binary | Gray |
|---|---|---|
| 0 | 000 | 000 |
| 1 | 001 | 001 |
| 2 | 010 | 011 |
| 3 | 011 | 010 |
| 4 | 100 | 110 |
| 5 | 101 | 111 |
| 6 | 110 | 101 |
| 7 | 111 | 100 |
Binary → Gray: MSB same; each next Gray bit = XOR of current and previous binary bit.
Gray → Binary: MSB same; each next binary bit = XOR of Gray bit and previous binary result.
Signed Number Representations
8.1 Unsigned Numbers
- No sign bit — all values positive
- n-bit range: 0 to 2ⁿ - 1
8.2 Sign-Magnitude
- MSB = sign (0=+, 1=-)
- Remaining bits = magnitude
- Two zeros: +0 and -0
- n-bit range: -(2^(n-1)-1) to +(2^(n-1)-1)
Example (6-bit): -31 = 1 11111, +31 = 0 11111
8.3 1's Complement
- Positive: normal binary
- Negative: 1's complement of magnitude
- Two zeros — ambiguous
- Same range as sign-magnitude
8.4 2's Complement (Standard)
- Positive: normal binary
- Negative: 2's complement of magnitude
- Single zero
- n-bit range: -2^(n-1) to +2^(n-1)-1
Example (6-bit): -32 = 100000, +31 = 011111
8085 and most microprocessors use 2's complement for signed arithmetic.
Continue learning
Related notes
Put this topic into timed practice
Open mock tests when you want full-exam pacing, or keep drilling in practice mode.