18 ms·
Here's a very brief description of two's complement that also happens to be a complete description: Two's complement is ordinary integer arithmetic. There is n
by thaumasiotes 3y ago
Here's a very brief description of two's complement that also happens to be a complete description:
Two's complement is ordinary integer arithmetic. There is no difference between two's complement arithmetic and unsigned arithmetic. All calculations are literally identical.
Unsigned integer arithmetic is modular arithmetic with equivalence classes having labels between 0 (inclusive) and 2^n (exclusive), while two's complement arithmetic is the same thing, but the equivalence classes have labels between negative 2^{n-1} (inclusive) and 2^{n-1} (exclusive).
Here's a table of three-bit values with "unsigned" and "two's complement" labels:
100 4 -4
101 5 -3
110 6 -2
111 7 -1
000 0 0
001 1 1
010 2 2
011 3 3
100 4 -4
101 5 -3
110 6 -2
111 7 -1
Note that when you're working in mod 8, 5 and -3 are the same value, so this is nothing but a labeling difference.