Electronic – Why does signed (2’s complement) binary multiplication have different procedure than unsigned

arithmetic-divisionbinaryfixed-pointvhdl

The 2's complement binary multiplication does not have same procedure as unsigned if the both operands do not have the same sign. What is the logic behind that?

Does special consideration apply to division also when we carry out division with 2's complement numbers?

Best Answer

The 2's complement binary multiplication does not have same procedure as unsigned

In modulo 2n arithmetic -1 and 2n-1 are equivilent. It follows that if the output is the same size as the input then we can used a modulo 2n multiplier for both signed and unsigned operations.

However if the output is larger than the inputs this property no longer holds. Consider for example multipying the 8 bit number 11111111 (255 if interpreted as straight binary, -1 if interpreted as 2's complement) with itself to produce a 16 bit result. For signed numbers the correct result is 0000000000000001. However for unsigned numbers the correct result is 1111111000000001 (65025 in decimal)

If you want to think of this in modular arithmetic terms you can note that -1 and 255 are the same modulo 256 but different modulo 65536.

This is why when you look at (for example) the arm instruction set you see only one 32*32->32 multiply instruction but two different 32*32->64 multiply instructions.

Does special consideration apply to division also when we carry out division with 2's complement numbers?

Division (in the sense we think of it on computers) is not a modular arithmetic operation. So there is no reason to expect an equivilence between signed and unsigned division and indeed there isn't one.

Again to give an example consider 11111110 / 00000010 . In unsigned arithmetic this would result in 01111111 (127) in signed arithmetic it would result in 11111111 (-1)