Demonstration of Unsigned to Signed Binary Multiplication

binarymultiplication

I am trying to deepen my knowledge about multiplication with signed binary numbers (in two's complement) and as I was following along a video about the multiplication of 4-bit signed binary numbers, I couldn't really understand how and why some steps were taken.

Right in the beginning of the demonstration (image right below) I fall short.

sign extension and last partial products subtracting

  1. I think I understand the sign extension, that happens because we are working with numbers in two's complement and the most significant bit must be propagated. (correct?)

  2. Why is the last line of partial products subtracting instead of adding? Wouldn't it ruin multiplication between two positives? (I've tested the circuit based on this demonstration and it works for two positive numbers as well.)

  3. My last question resides in the simplification of those 1s (image below):
    Simplifying 1s

    What I think was done was:

  • (For a reason I don't know/understand) we consider 01111 and not 1111.
  • Calculate 2's complement of 01111 to 10001 (to add and not subtract).
  • Finally add 10001 and 00001 to result in 10010.
    enter image description here
    If in fact my "guess" (that was more of trying until I found something that seemed to work) is correct, why do we first extend these numbers with one more bit?

Best Answer

  1. I think I understand the sign extension, that happens because we are working with numbers in two's complement and the most significant bit must be propagated. (correct?)

Break down \$Y\$ such that \$Y=-y_3\cdot 2^3+\sum_{i=0}^2 y_i\cdot 2^i\$. But don't break down \$X\$. Just take it as a 2's complement signed value. Then \$X\cdot Y=y_0\cdot \underline{X\cdot 2^0}+y_1\cdot \underline{X\cdot 2^1}+y_2\cdot \underline{X\cdot 2^2}-y_3\cdot \underline{X\cdot 2^3}\$. Note that the first three lines are just a shifted version of \$X\$ (times an unsigned bit in \$Y\$) and, since \$X\$ is signed, the result must be sign-extended. The last term is again just a sign-extended result but in this case must be subtracted. This explains all four of the lines in case 1.

  1. Why is the last line of partial products subtracting instead of adding? Wouldn't it ruin multiplication between two positives? (I've tested the circuit based on this demonstration and it works for two positive numbers as well.)

See above.

  1. My last question resides in the simplification of those 1s

$$\begin{align*}X\cdot Y&=\left(-x_3\cdot 2^3+\sum_{i=0}^2 x_i\cdot 2^i\right)\cdot \left(-y_3\cdot 2^3+\sum_{i=0}^2 y_i\cdot 2^i\right) \\\\ &=x_3y_3\cdot2^6\\&\quad +\left(\sum_{i=0}^2 x_i\cdot 2^i\right)\cdot\left(\sum_{i=0}^2 y_i\cdot 2^i\right)\\&\quad-y_3\cdot\left(\sum_{i=0}^2 x_i\cdot 2^i\right)\cdot 2^3\\&\quad-x_3\cdot\left(\sum_{i=0}^2 y_i\cdot 2^i\right)\cdot 2^3 \\\\ &=x_3y_32^6+\sum_{i=0}^2 \sum_{j=0}^2 x_iy_j 2^{i+j}-y_32^3\sum_{i=0}^2 x_i 2^i-x_32^3\sum_{i=0}^2 y_i2^i \end{align*}$$

Or, in table form:

$$\begin{matrix} &2^7&2^6&2^5&2^4&2^3&2^2&2^1&2^0\\ \hline \\ +&0&x_3y_3&0&0&0&x_2y_0&x_1y_0&x_0y_0 \\\\ +&0&0&0&0&x_2y_1&x_1y_1&x_0y_1&0 \\\\ +&0&0&0&x_2y_2&x_1y_2&x_0y_2&0&0 \\\\ -&0&0&x_2y_3&x_1y_3&x_0y_3&0&0&0 \\\\ -&0&0&x_3y_2&x_3y_1&x_3y_0&0&0&0 \end{matrix}$$

Complement and increment the last two lines:

$$\begin{matrix} &2^7&2^6&2^5&2^4&2^3&2^2&2^1&2^0\\ \hline \\ +&0&x_3y_3&0&0&0&x_2y_0&x_1y_0&x_0y_0 \\\\ +&0&0&0&0&x_2y_1&x_1y_1&x_0y_1&0 \\\\ +&0&0&0&x_2y_2&x_1y_2&x_0y_2&0&0 \\\\ +&1&1&\overline{x_2y_3}&\overline{x_1y_3}&\overline{x_0y_3}&1&1&1 \\\\ +&0&0&0&0&0&0&0&1 \\\\ +&1&1&\overline{x_3y_2}&\overline{x_3y_1}&\overline{x_3y_0}&1&1&1 \\\\ +&0&0&0&0&0&0&0&1 \end{matrix}$$

Combine the constants:

$$\begin{matrix} &2^7&2^6&2^5&2^4&2^3&2^2&2^1&2^0\\ \hline \\ +&0&x_3y_3&0&0&0&x_2y_0&x_1y_0&x_0y_0 \\\\ +&0&0&0&0&x_2y_1&x_1y_1&x_0y_1&0 \\\\ +&0&0&0&x_2y_2&x_1y_2&x_0y_2&0&0 \\\\ +&0&0&\overline{x_2y_3}&\overline{x_1y_3}&\overline{x_0y_3}&0&0&0 \\\\ +&0&0&\overline{x_3y_2}&\overline{x_3y_1}&\overline{x_3y_0}&0&0&0 \\\\ +&1&0&0&1&0&0&0&0 \end{matrix}$$

Clear, now?