2's complement binary multiplication

3.2k Views Asked by At

I am a little confuse with how do we perform signed 2's complement multiplication.

         10 1101        -19
       x 11 0001     x  -15
      ----------------  ------
          101101         285
         000000
        000000
       000000
      101101
     101101
    ----------------
   100010011101

Adding all the calculations I get "100010011101" as stated which is not 285 signed, why?

3

There are 3 best solutions below

2
On BEST ANSWER

You're doing unsigned arithmetic. To do two's complement, you need to treat the numbers as having infinitely repeating sign digits:

            ...1111101101
            ...1111111001
-------------------------
            ...1111101101
           ...0000000000
          ...0000000000
         ...0000000000
        ...1111101101
       ...1111101101
      ...1111101101
     ...1111101101
    ...1111101101
   ...1111101101
           :
-------------------------
      ...0000000100011101

And you need to continue the process until it reaches a fixed point (where further bits computed will all be the same.) It turns out that this will always happen by the time you produce n+m bits of output (where n and m are the sizes of the multiplicands in bits), so this is easily bounded.

0
On

If you want the correct result you have to do a sign extension of the numbers to twice as many bits.

                       111111101101        
               x       111111110001
                       ------------
                       111111101101
                      000000000000
                     000000000000
                    000000000000
                   111111101101
                  111111101101
                 111111101101
                111111101101
               111111101101
              111111101101
             111111101101
      +     111111101101
            ----------------------
           000000000000000100011101
                            
0
On

Extend the bits to full width and truncate

Here is a 4 bit example:

  1110   -2
* 1111   -1
------   --
  1110
  110
  10
+ 0
------
  0010    2

now repeat your example using 8 bits if multiplying bytes, 16 bits if multiplying shorts