๐ข Signed Number Representations in Binary
๐ง What Are Signed Numbers?
Signed numbers allow binary systems to represent both positive and negative values. The most significant bit (MSB) typically acts as the sign bit:
0โ positive1โ negative
๐ง Common Encoding Schemes
1๏ธโฃ Sign-Magnitude
+5 โ 0101
โ5 โ 1101- MSB is the sign; remaining bits are magnitude
- Two representations of zero:
0000(+0),1000(โ0)
2๏ธโฃ Oneโs Complement
+5 โ 0101
โ5 โ 1010 (bitwise NOT of +5)- Negative numbers are bitwise inverses of positives
- Two zeros:
0000(+0),1111(โ0) - Requires end-around carry in addition
3๏ธโฃ Twoโs Complement โ (Most Common)
+5 โ 0101
โ5 โ 1011 (bitwise NOT of +5 โ 1010, then +1)- Single representation of zero:
0000 - Clean arithmetic: no special rules for subtraction
- Range:
โ2โฟโปยนto2โฟโปยน โ 1
๐งฎ Range Comparison (4-bit)
| Encoding | Min Value | Max Value | Zero Count |
|---|---|---|---|
| Sign-Magnitude | โ7 | +7 | 2 |
| Oneโs Complement | โ7 | +7 | 2 |
| Twoโs Complement | โ8 | +7 | 1 โ |
Last updated on