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?

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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?
@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.
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

Comments

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
                            

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.