Update
This commit is contained in:
parent
a7b086a309
commit
7a4c69819f
14 changed files with 59 additions and 18 deletions
|
@ -4,7 +4,7 @@ Two's complement is an elegant way of encoding signed (i.e. potentially negative
|
|||
|
||||
Why is two's complement so great? Its most notable advantages are:
|
||||
|
||||
- **There if only one [zero](zero.md) value** (while other encodings such as sign-magnitude and one's complement have positive and negative zero which wastes values and complicates algorithms).
|
||||
- **There is only one [zero](zero.md) value** (while other encodings such as sign-magnitude and one's complement have positive and negative zero which wastes values and complicates algorithms).
|
||||
- **Highest bit indicates the number sign** in the same way as e.g. in sign-magnitude and one's complement representations, i.e. determining whether a number is positive or negative is just as easy as in the more naive representations.
|
||||
- **Addition, subtraction and multiplication (both signed and unsigned!) work the same as with unsigned representation and overflow naturally**, i.e. we can have exactly the same hardware for these operations as for unsigned numbers and we don't even have to know whether the number is supposed to be unsigned or signed (this of course does NOT hold for any operation, e.g. division or comparison). Operations such as decrementing 0 or incrementing -1 correctly yield -1 and 0, respectively, without any special conditions. Subtraction can simply be done as adding a negated value. One's complement and sign-magnitude have to have special conditions for many of these situations.
|
||||
- **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.)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue