28.1k views
1 vote
Given x = -20 and y = -16, use 6-bit two’s complementto compute the followings:

a)z = x + y
b) z = x - y
c) z = -x +y
d) z = -x - y
For each case, check for overflow, and convert z to decimal

1 Answer

2 votes

Final answer:

By representing -20 and -16 in 6-bit two's complement, we can perform arithmetic operations and convert the results back to decimal. Overflow is checked by ensuring the result fits within 6 bits. No overflow occurs in the given calculations.

Step-by-step explanation:

To compute the operations using 6-bit two's complement for x = -20 and y = -16, we first need to represent these numbers using 6-bit two's complement notation.

x = -20 is represented as 111011 because the 6-bit two's complement of 20 (001010) involves inverting the digits (110101) and adding 1 (111011).

y = -16 is represented as 111100 for the same reason: the complement of 16 (001000) is 110111, and adding 1 gives us 111100.

Calculations:

  • z = x + y: 111011 + 111100 = (1)110111. The leftmost digit is discarded since we're using 6 bits, leaving 110111, which is the 6-bit two's complement of 33 (the overflow bit is indicated, but it doesn't change the result in this case).
  • z = x - y: 111011 + 000100 = 111111, which is -1 in two's complement notation, indicating no overflow.
  • z = -x + y: 000101 + 111100 = 000001, which is 1 in two's complement notation, indicating no overflow.
  • z = -x - y: 000101 + 000100 = 001001, which is 9 in two's complement notation, indicating no overflow.

For each operation, after obtaining the result in two's complement, we convert z back to decimal and check for overflow. Operations resulting in a number that requires more than 6 bits indicate an overflow.

User Claasz
by
8.8k points