$\require{cancel}$
One's complement and Two's complement
Sorry, I have no real good on line references. I am using Kumar for this.
As we saw with 9's and 10's complment for base 10, we can perform addition and subtraction without the rules based system sign-magnitude requires.
The equivelent system is 1's complement and 2's complement.
This system
Requires a fixed number of bits. So 3 bit 2's compliement for example.
Like 9's complemnt and 10's complement we subtract from the radix-1 (remember 9) but in this case, we subtract from 1.
This is equivelent to flip the bits
1-1 = 0
1-0 = 1
Which, by the way, is a not gate!
For 2's complement, add one.
Examples:
Find the 4 bit 1's and 2's complement of -4
4 = 0100
2
-4 = 1011
2
in 1's complement notation
-4 = 1100
2
in 2's complement notation
0100
2
=> 1011
2
(a) 1011
2
+1 = 1100
2
(b)
What does the bit pattern 1010
2
represent in 1's complement and 2's complement?
1010
2
is -5 in 1's complement
1010
2
is -6 in 2's complement.
1010
2
=> 0101
2
= 5 0101
2
+1 = 0110
2
= 6
The trick is "flip the bits and add 1" for 2's complement.
We have an indicator of the sign in both 1's and 2's complemnt
if the msb is 0, the rest of the bits are the magnitude
If the msb is 1, take the 1 or two's complement to find the magnitude
This rule fails in one case for two's complement,
for the bit pattern 10...0 in any number of bits.
Assume 4 bits.
1000
2
-> 0111
2
+1 -> 1000
2
In this case, it represents -2
-3
= -8