Two’s Complement Arithmetic Convert the given signed decimal numbers to 8-bit Two’s Complement binary numbers.

Two’s Complement Arithmetic Convert the given signed decimal numbers to 8-bit Two’s Complement binary numbers. Calculate the sum and difference of the Two’s Complement binary numbers. For each calculation, indicate “overflow” if overflow occurred. All work should be done in binary. Show your work. Complete the table given below. Decimal Two’s Complement Binary Sum Difference A B A B A+B A-B +103 -58 +94 +27

The Correct Answer and Explanation is:

Step 1: Convert to 8-bit Two’s Complement

Two’s complement binary can represent numbers from -128 to +127 in 8 bits.

Decimal8-bit Two’s Complement
+10301100111
-5811000110
+9401011110
+2700011011

Step 2: Perform Binary Addition (A + B)

Case 1: A = +103 (01100111), B = -58 (11000110)

pgsqlCopyEdit   01100111
+  11000110
-----------
  100111101  → 9 bits, drop the overflow bit (carry out)

Result: 00111101 → +61 (No overflow)

Case 2: A = +94 (01011110), B = +27 (00011011)

markdownCopyEdit   01011110
+  00011011
-----------
   01111001 → +121 (No overflow)

Step 3: Perform Binary Subtraction (A – B)

This is done by adding A + (-B) (i.e., the two’s complement of B).

Case 1: A = +103 (01100111), B = -58 → -(-58) = +58 → 00111010

markdownCopyEdit   01100111
+  00111010
-----------
   10011101 → -99 (Overflow! Because +103 - (-58) = 161, which is beyond +127)

Case 2: A = +94 (01011110), B = +27 → -27 = 11100101

markdownCopyEdit   01011110
+  11100101
-----------
   01000011 → +67 (No overflow)

Final Table

Decimal ADecimal BA (Binary)B (Binary)A + B (Binary)A – B (Binary)Overflow
+103-58011001111100011000111101 (+61)10011101 (-99)Yes (A-B)
+94+27010111100001101101111001 (+121)01000011 (+67)No

📘 Explanation

In two’s complement arithmetic, signed integers are represented in binary using a fixed number of bits. For 8-bit representations, the range is from -128 (10000000) to +127 (01111111). Positive numbers are represented as usual in binary, while negative numbers are formed by inverting all bits of the absolute value and adding 1.

To compute sums and differences in binary, we perform standard binary addition. Subtraction is handled by converting the number to be subtracted (B) into its two’s complement, then adding it to A. The result is interpreted as a signed 8-bit number.

Overflow can occur in two’s complement arithmetic when the true result is out of range for the number of bits available. For 8-bit values, this means any result less than -128 or greater than +127 will cause overflow. Importantly, overflow detection is not based on the carry out but on the sign bits: if the signs of A and B are the same but the result has a different sign, overflow has occurred.

In the first case (A = +103, B = -58), the sum is 103 + (-58) = +45, and subtraction becomes 103 – (-58) = 161, which exceeds the maximum 8-bit value of +127, resulting in overflow. In the second case (A = +94, B = +27), all values are within range, and no overflow occurs.

Thus, understanding how two’s complement works is crucial for reliable binary arithmetic in digital systems and computer programming

.

Scroll to Top