This commit is contained in:
Miloslav Ciz 2025-05-07 21:16:44 +02:00
parent 4d545b6845
commit 8b530b5952
20 changed files with 206 additions and 24 deletions

View file

@ -10,7 +10,7 @@ Why is two's complement so great? Its most notable advantages are:
- **Positive values and zero are the same as the straightforward unsigned representation**, i.e. it is "backwards compatible" with the straightforward representation. For example the 4 bit value `0011` represents number 3 in two's complement just like it does in a normal unsigned binary number. (This also holds in sign-magnitude and one's complement.)
- **Multiplying by -1 is still relatively simple** -- even though it is a tiny bit more expensive than in one's complement or sign-magnitude, it is still pretty straightforward (only requires two operations instead of one) and in [hardware](hardware.md) it can be implemented just as fast.
TODO: disadvantages?
TODO: disadvantages? Sign extensions maybe.
*N* bit number in two's complement can represent numbers from *-(2^N) / 2* to *2^N / 2 - 1* (including both). For example with 8 bits we can represent numbers from -128 to 127.
@ -32,3 +32,8 @@ The following is a comparison of the different representations, notice the shini
| 101 | 5 | -3 | -1 | -2 | 1 |
| 110 | 6 | -2 | -2 | -1 | 2 |
| 111 | 7 | -1 | -3 | -0 | 3 |
## See Also
- [posit](posit.md)
- [conum](conum.md)