How to Do Signed Binary Addition/Subtraction in 2's Complement Form

General Steps for Addition/Subtraction in 2’s Complement Form

The signed 2โ€™s complement form is the standard method for handling signed binary arithmetic, enabling seamless addition and subtraction of positive and negative numbers. By converting subtraction into addition, 2โ€™s complement simplifies the process and ensures accurate results. Below are the general steps for performing addition or subtraction in 2โ€™s complement form:

  1. Express the Operation: Rewrite the operation as an addition problem. For example, to compute \(\mathsf{A โˆ’ B}\), express it as \(\mathsf{A + (โˆ’B)}\). Similarly, for \(\mathsf{โˆ’A โˆ’ B}\), rewrite it as \(\mathsf{(โˆ’A) + (โˆ’B)}\).
  2. Perform Addition: Convert both numbers to their 2โ€™s complement form and add them using standard binary addition.
    • If there is an end-carry, discard it. The remaining digits represent the result, which may be positive or negative.
    • If there is no end-carry, the result is the direct output of the addition, also potentially positive or negative.

This method leverages the 2โ€™s complement systemโ€™s ability to handle signed numbers efficiently, making arithmetic operations consistent and reliable.

Converting Between Decimal and 2โ€™s Complement Form

When working with decimal inputs and expecting decimal outputs, additional steps are needed to convert numbers to and from 2โ€™s complement form. The number of bits used for representation is critical to avoid overflow and ensure accurate results.

Determining the Number of Bits

If the problem specifies the number of bits (e.g., 6 bits), use that as the basis for representation. If no bit count is provided, determine the number of bits required as follows:

  • Identify the largest number (ignoring its sign) in the problem.
  • Convert this numberโ€™s magnitude to binary to find the minimum number of bits (\(\mathsf{n}\)) needed to represent it.
  • Add one bit for the sign and an additional bit to accommodate potential overflow, resulting in \(\mathsf{n+2}\) bits. This ensures the sum of two n-bit numbers, which may require up to \(\mathsf{n+1}\) bits, fits within the representation without overflow issues.

Converting Decimal to 2โ€™s Complement

To convert a decimal number to its 2โ€™s complement form:

Converting 2โ€™s Complement to Decimal

After performing the addition, the result is in 2โ€™s complement form. To convert it back to decimal:

  • Check the Sign Bit: If the MSB is 0, the number is positive; convert the remaining bits directly to decimal and prefix a \(\mathsf{+}\) sign.
  • Negative Numbers: If the MSB is 1, the number is negative. To convert, take the 2โ€™s complement of the result (invert all bits and add 1), convert the resulting positive magnitude to decimal, and prefix a \(\mathsf{-}\) sign.
  • Alternative Method: Use a modified binary-to-decimal conversion by assigning a weight of \(\mathsf{-2^{n-1}}\) to the MSB (instead of \(\mathsf{+2^{n-1}}\)) and standard weights (\(\mathsf{2^{n-2}, 2^{n-3},}\) etc.) to the remaining bits. Sum these values to obtain the decimal result.

This approach ensures accurate conversion between decimal and 2โ€™s complement forms, accounting for the sign bit and preventing overflow errors.

Example 1: Perform 3-4 using 6-bit signed 2’s complement method

this image shows the solution of 3-4 using 6-bit signed 2's complement method

Example 2: Perform 12+2 using 6-bit signed 2’s complement method

this image shows the solution of 12+2 using 6-bit signed 2's complement method

Example 3: Perform -5-6 using 6-bit signed 2’s complement method

this image shows the solution of -5-6 using 6-bit signed 2's complement method

Example 4: Perform -8+15 using 6-bit signed 2’s complement method

this image shows the solution of -8+15 using 6-bit signed 2's complement method

Example 5: Perform 15-8 using 6-bit signed 2’s complement method

this image shows the solution of 15-8 using 6-bit signed 2's complement method