Signed Magnitude, Two's & One's complement
Overview
| Binary | Decimal | SM | 1's Complement | 2's Complement |
|---|---|---|---|---|
| 0000 | 0 | 0 | 0 | 0 |
| 0001 | 1 | 1 | 1 | 1 |
| 0010 | 2 | 2 | 2 | 2 |
| 0011 | 3 | 3 | 3 | 3 |
| 0100 | 4 | 4 | 4 | 4 |
| 0101 | 5 | 5 | 5 | 5 |
| 0110 | 6 | 6 | 6 | 6 |
| 0111 | 7 | 7 | 7 | 7 |
| 1000 | 8 | -0 | -7 | -8 |
| 1001 | 9 | -1 | -6 | -7 |
| 1010 | 10 | -2 | -5 | -6 |
| 1011 | 11 | -3 | -4 | -5 |
| 1100 | 12 | -4 | -3 | -4 |
| 1101 | 13 | -5 | -2 | -3 |
| 1110 | 14 | -6 | -1 | -2 |
| 1111 | 15 | -7 | -0 | -1 |
SM and 1's complement has representations of '0'
So it's not used
Trick to calculate 2's complement
See [[#2's complement#Method 2]]
Signed Magnitude (SM)
Most significant bit (MSB) (Left most bit) represents the sign.
One's complement
From [[#Signed int]],
If MSB == 0
- Represents a positive number.
- Simply convert to decimal.
If (MSB == 1) - Represents a negative number
- So, flip all of the bits
- Then convert to the decimal number (And put the negative sign)
| Decimal | One's complement |
|---|---|
| 2 | 0010 |