How do I multiply positive and negative numbers? (in n's complement)

In summary, the complement of a number with m digits in base r is rm - D. In two's complement, the weights are -23 22 21 20. In three's complement, the weights are 1 for a 1 or a 2 in the "sign bit", and 10 - 1 for a 0 or a 1. My question is why do we have to complement the most significant bit to find out what we use to multiply the weight of that position?
  • #1
purtsuorts
3
0

Homework Statement


I need to understand how signed multiplication is done in 2's to 10's complement.

Homework Equations


The complement D' of a number D with m digits in base r is rm - D.
So, the complement of 010 in binary (2 in dec) is 1000 - 010 = 110 (-2, but 6 if it were unsigned). We add a leading 0 because there is no such thing as positive 2 in 2-bit 2's complement.
The complement of 20 in ternary (6) is 10 (3) because they sum to 100 (9, or 32).

The Attempt at a Solution


I understand how multiplication works in binary, but I'm having trouble figuring out how it extend to higher bases. For example, 12 * 22 (5 * -1) in three's complement. I know that it is the complement of 12, which is 11, but I have no idea how to work this out as a multiplication problem. The particular homework problem I'm being asked to solve is 202 * 121 (-7 * -11), but obviously I'm not really looking for an answer here.
 
Physics news on Phys.org
  • #2
Okay, never mind, I figured out how multiplication works.
But now I have another question.
I know that in 4 bit unsigned binary, the number places have weights of 23 22 21 20 just like in decimal with 103 102 101 100. However, in two's complement, the weights are -23 22 21 20, which is why 1111 = -23 22 21 20 = -8 + 4 + 3 + 1 = -1. But that isn't the whole story. We aren't multiplying -23 by 1, we are multiplying it by the COMPLEMENT of 1, which is 10 - 1, or 1. So nothing changed.
But in a negative three's complement number, we can have either a 1 or a 2 in that "sign bit", which means that that final complementation does matter because 10 - 1 = 2 and 10 - 2 = 1.
My question is, why do we have to complement the most significant bit to find out what we use to multiply the weight of that position?

edit: Come to think of it, would this be better in the number theory section? But this is homework and it is for a computer science class...
 
  • #3
How did you come up with the answer?

I can see that positive multiplication in three's complement is just plain multiplication without complementing the answers and without using sign extension, but can't seem to figure out any type of negative multiplication (- * +, + * -, - * -).
 
  • #4
It ties a bit into my second post. Our usual method of multiplication assumes that digits are assigned a specific weight based on their position. As you probably know, when we move our partial product computations to the left while doing our nostalgic primary-school multiplication algorithm, we are actually multiplying by a power of 10. It turns out that complement number systems can be looked at like our usual position based number system, except that final weight is negative. With that in mind, all you need to do is find the complement of that number to get its magnitude which is what you're supposed to multiply your multiplicand with. The problem is that this only works for negative numbers in three's complement, and numbers with a 1 in their "sign bit" seem to be arbitrarily positive or negative.

Also, I see that you happen to have one post. Please don't tell me that this topic also happens to be a critical part of a class you are taking, and your professor also happens to expect you to have innate knowledge of race conditions inside buggy circuit simulation programs.
 
  • #5


To multiply positive and negative numbers in n's complement, the following steps can be followed:

1. Convert the numbers to their n's complement form. For example, if we are working with 8-bit 2's complement, -7 would be represented as 11111001 and -11 would be represented as 11110101.

2. Multiply the numbers as you would normally in binary, starting from the rightmost bit. Ignore any carry bits.

3. If the result is larger than the maximum number that can be represented in n bits, take the n least significant bits and add 1 to the leftmost bit. This is called "wrapping around".

4. Convert the result back to its n's complement form. If the leftmost bit is 1, take the n least significant bits and subtract them from 2n. For example, in 8-bit 2's complement, if the result is 11111111, the actual value would be 11111111 - 256 = -1.

Let's use the given example of 202 * 121 (-7 * -11) in 8-bit 2's complement:

1. 202 is represented as 11001010 and 121 is represented as 01111001.

2. Multiplying these numbers gives us 01101000, which is the binary representation of 104.

3. Since 104 is within the range of representable numbers in 8-bit 2's complement, we don't need to do any wrapping around.

4. Converting 104 to its 8-bit 2's complement form gives us 01101000, which is the binary representation of 104. This is the same as the original number, so the final result is 104.

In summary, to multiply positive and negative numbers in n's complement, we can simply convert the numbers to their n's complement form, multiply them as usual, and then convert the result back to its n's complement form.
 

1. How do I multiply a positive number by a negative number in n's complement?

The first step is to convert both numbers to their n's complement form. Then, multiply the numbers as you normally would, ignoring any carry that may occur. Finally, take the n's complement of the result to get the final answer.

2. Can I multiply two negative numbers in n's complement?

Yes, you can. The process is the same as multiplying a positive and a negative number. Convert both numbers to their n's complement form, multiply them, and take the n's complement of the result.

3. What if one of the numbers is zero?

If one of the numbers is zero, the product will always be zero. However, you still need to convert the number to its n's complement form before multiplying.

4. How do I handle overflow when multiplying positive and negative numbers in n's complement?

Overflow can occur when the product of two numbers is larger than the maximum value that can be represented in n's complement form. To handle overflow, you can increase the number of bits used to represent the numbers before performing the multiplication.

5. Can I use n's complement to multiply decimal numbers?

No, n's complement is only used for binary numbers. To multiply decimal numbers, you can use the standard multiplication algorithm.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
24
Views
6K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
13
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
  • Programming and Computer Science
Replies
1
Views
937
  • Precalculus Mathematics Homework Help
Replies
6
Views
3K
Back
Top