Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To perform division with signed integers alone and achieve the same result as with unsigned division, we need to use the concept of two's complement.

Two's complement is a mathematical operation that allows us to represent negative integers by inverting all the bits and adding one to the result.

To divide two signed integers using two's complement:

  1. Convert the dividend and divisor to their two's complement representation.
  2. Divide the two numbers using unsigned division.
  3. If the result is negative, convert it back to two's complement.

For example, let's divide -6 by 3 using two's complement:

  1. Convert -6 and 3 to their two's complement representation: -6 = 11111010 (two's complement) 3 = 00000011 (two's complement)

  2. Divide the two numbers using unsigned division: 1 1 1 1 1 0 1 0 (dividend)

    ÷0 0 0 0 0 0 1 1 (divisor)

    0 0 0 1 1 (remainder) 1 1 0 0 1 (quotient)

  3. The result is negative (-3) because the dividend was negative. Convert it back to two's complement: -3 = 11111101 (two's complement)

Therefore, -6 ÷ 3 = -3 using two's complement.