But to be able to do subtraction as addition of a complement, we
have to use TWO's complement, not ones. If you are mathematically
inclined, please look below my signature for the proof.
For the rest, note that the two's complemment of 3 is
1101. when we do
6 = 0 1 1 0
-3 = 1 1 0 1
-------------
1 0 0 1 1
of which we use only the last 4 bits to get 3, the correct answer.
Himanshu Nautiyal
http://www.cs.washington.edu/homes/nautiyal
------------------------------------------------------------------------
sketch of proof. Dont worry if you dont understand it.
Note that given 8 bits, we can represent numbers from -128 to 127. Notice
that for a given negative number, say -3, its representation (ie. the
two's complement i.e. 11111101, when considered as a non-negative number is
just 253 = 256 - 3. So when do x - 3 by doing x + (-3) as non-negative
numberrs, we are actually adding
x + (256 - 3)
= (x - 3) + 256.
The 256 appears as a carry out from the 8th bit, which we dont look at
anyway (except to check for overflow), thus we only look at the (x - 3)
part, giving the right answer.
You may have observed that the one's complement is always 1 smaller than
the two's compl. So, -3 is represented by 255 - 3.
On doing x - 3 by representing -3 as its ones complement, we get
x + (255 - 3)
= (x - 3) + 255
= (x - 3 - 1) + 256
and the 256 is discarded as a carry out from 8th bit. So, you got
(x - 3 - 1) ie. one less than what you intended.