Adding and subtracting two additions

Using a six-bit representation of one and two additions, I am trying to solve the following problem:

12 - 7 

Now I take 12 binary and 7 in binary format.

12 = 001100 - 6 bit 
7 =  000111 - 6 bit

Then, if I flipped a bit for two additions and added one?

12 = 110011 ones complement 
     +    1
    -------
     001101

7  = 111000 ones complement 
    +     1
   ---------
      111001

then add these two additions together

 001101
+111001
-------
1000110 = overflow? discard the last digit?  If so I get 5

Now, if I have a number like

-15 + 2

Then I would add the sign value on the MSB if it is zero?

as:

-15 = 001111 6 bit

Would I add 1 at the end here before flipping the bits?

  = 101111
+5
source share
2 answers

, . 12 - 7 12 + (-7). , -7 +12:

12  001100
-7  111001   -- to get this, invert all bits of 7 (000111) and add 1
----------
 5 1000101

( ), : 000101, 5, .

-15 + 2 , -15:

15  001111
    110000   -- inverted bits
    110001   -- add 1

:

-15  110001
  2  000010
-----------
res  110011

, res -13, , ( MSB). ( , 1):

res  110011
     001100  -- inverted bits
     001101  -- add 1

, 13, .

+14

. , .

+2

All Articles