Search code examples
binarydivisionmultiplicationbittwos-complement

2's complement binary multiplication


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?


Solution

  • 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.