How does multiplication with 2's complement work?

  • Context: Calculators 
  • Thread starter Thread starter PLAGUE
  • Start date Start date
PLAGUE
Messages
37
Reaction score
2
TL;DR
Why this way of multiplication gives the correct result?
I recently learned of a multiplication method of signed numbers using 2's complement. Here is the answer. What I want to know is how does this multiplication work? I understand that two's complement is $2^n−N$. I understand how subtraction with complements works. But how does the multiplication give accurate result here?

Also, would this method work if one of the numbers is not negative?
 
Computer science news on Phys.org
When you multiply 2s-complement numbers, you need to do "sign extension" - and that is shown in the link you provided. I have provided more a more detailed explanation below.

Using the 4-bit examples, if all you want is a 4-bit result, then you are doing a modulo 16 multiply - and the result will be correct regardless of how you interpret the sign bit. So, for example, binary 1111 x 1111 = 0001 it correct for both -1 x -1 modulo 16 and 15x15 modulo 16.

But normally, when you multiply two words, you want a product that includes double the number of bits. So, as with our example, you would want 1111x1111 = 00000001 or 11100001, depending on whether the 1111's are unsigned (15s) or 2's complement signed (-1s).

So, to do the signed multiply, you:
1) Do the regular multiply (yielding 11100001). This is the simple modulo-256 result.
2) Since the first term is negative, it was too big by 2*(1000), and so the product was too big by 2*(1000)*2nd term. Correct this by subtracting 10000 times the second term (11110000) still using modulo-256 arithmetic (yielding 11110001).
3) Similarly, since the second term is negative, it was too big by 2*(1000), and so the product was too big by 2*(1000)*1st term. Correct this by subtracting 10000 times the first term (11110000) still using modulo-256 arithmetic (yielding 00000001, your final result).
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
5
Views
2K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
Replies
6
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
1
Views
2K
Replies
3
Views
3K