Signed Numbers & Two's Complement

Digital systems use two's complement to represent negative numbers. This method allows for simple addition and subtraction operations without needing special handling for negative numbers. The leftmost bit (most significant bit) serves as the sign bit, where 1 indicates negative and 0 indicates positive.

Converting 42 to 8-bit Two's Complement

Step 1: Original Number
0010 1010
Start with absolute value: 42
Step 2: One's Complement
1101 0101
Flip all bits
Step 3: Two's Complement
1101 0110
Add 1 to one's complement
Final Result:
Binary:
0010 1010
Decimal:
42

Two's Complement Properties

  • Most significant bit (leftmost) is the sign bit (0 = positive, 1 = negative)
  • Positive numbers are represented normally
  • Negative numbers use two's complement representation
  • Range for 8-bit: -128 to 127
  • Adding a number and its two's complement equals 0
  • No special handling needed for addition/subtraction

Common Gotchas

  • Overflow can occur when result exceeds the bit width
  • Right-shifting negative numbers may need special handling
  • Converting between different bit widths needs sign extension
  • The smallest negative number has no positive counterpart