Sign and Magnitude
+5 = 00000101
-5 = 10000101
Problem: Two representations of zero (00000000 and 10000000)
Two's Complement
Represent -42 in 8-bit two's complement:
Step 1: Write +42 in binary
42 = 00101010
Step 2: Starting from the right, find the first 1 — keep everything from there rightward the same, flip everything to the left.
| Original | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Action | flip | flip | flip | flip | flip | flip | keep | keep |
| Result | 1 | 1 | 0 | 1 | 0 | 1 | 1 | 0 |
Answer: -42 in two's complement = 11010110
What decimal number does 11110011 represent?
Step 1: MSB is 1, so it's negative.
Step 2: To find the magnitude, convert back — keep everything up to and including the first 1 from the right, flip the rest.
| Original | 1 | 1 | 1 | 1 | 0 | 0 | 1 | 1 |
|---|---|---|---|---|---|---|---|---|
| Action | flip | flip | flip | flip | flip | flip | keep | keep |
| Result | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 |
Answer: 11110011 = -13
• Minimum: -128 (10000000)
• Maximum: +127 (01111111)
• One more negative number than positive!