Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To perform binary division for signed numbers using 2's complement, follow these steps:

  1. Convert both the dividend and divisor into their 2's complement representation. This involves inverting all the bits and then adding 1.

  2. Perform division as usual, ignoring the sign bit.

  3. Check the sign of the resulting quotient and remainder. If the signs of the dividend and divisor are different, the quotient and remainder must be negated.

  4. Convert the quotient and remainder back into their signed representation by inverting the bits and adding 1.

  5. Return the signed quotient and remainder.

For example, let's divide -9 by 3 using binary division with 2's complement:

-9 in 2's complement: 11110111 3 in 2's complement: 00000011

Divide as usual to get quotient 10 and remainder 1. Signs are different, so negate both quotient and remainder: Quotient becomes -10 in 2's complement: 11101110 Remainder becomes -1 in 2's complement: 11111111

Convert back to signed representation by inverting all bits and adding 1: Quotient is -6: 11111010 Remainder is -1: 11111111

Therefore, -9 divided by 3 is -6 with a remainder of -1.