2

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?

Gavin
  • 2,784
  • 6
  • 41
  • 78

3 Answers3

1

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.

Chris Dodd
  • 119,907
  • 13
  • 134
  • 226
  • I am confused how did you arrived at that answer. You did an additional right? I understand for bit 0 to 4. For bit 5 we have 2 ones, so we write a 0 and carry 1 to bit 6. Bit 6 has 3 ones + 1 carried forward = 4 ones, so what do we do now? – Gavin Nov 18 '14 at 15:43
  • @MaTaKazar: 4 is 100 in binary, so the result is 0 and carry the 10. You can think of this as carrying '2' to the next column, or carrying a bit up two columns -- the net result is the same. – Chris Dodd Nov 18 '14 at 18:47
0

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
                            
geometrian
  • 14,775
  • 10
  • 56
  • 132
Ortomala Lokni
  • 56,620
  • 24
  • 188
  • 240
0

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