Q2 · Binary arithmetic and overflow · solutions

Each part with its result, the overflow call, and the working.

Variation 1 2 pts · 6 min

The following are 2’s complement binary numbers. Perform the following operations and indicate if any of the operations generate overflow.

Q2.1 Binary Arithmetic/Overflow - part a 0.5
1010 + 11 =

Overflow?

  • Yes
  • No

1001 · overflow: No

11 is a 2-bit 2’s complement number, so it is −1; sign-extend to 1111. 1010 + 1111 = 11001, drop the carry: 1001 = −7. Negative + negative gave negative: no overflow.

Q2.2 Binary Arithmetic/Overflow - part b 0.5
0110 + 011 =

Overflow?

  • Yes
  • No

1001 · overflow: Yes

011 sign-extends to 0011. 0110 + 0011 = 1001. Positive + positive gave a negative pattern: overflow. 9 does not fit in 4 bits (max 7).

Q2.3 Binary Arithmetic/Overflow - part c 0.5
10000000 + 1110 =

Overflow?

  • Yes
  • No

01111110 · overflow: Yes

1110 is −2; sign-extend to 11111110. 10000000 + 11111110 = 101111110, drop the carry: 01111110 = +126. Negative + negative gave positive: overflow (−130 is below −128).

Q2.4 Binary Arithmetic/Overflow - part d 0.5
01001 - xC =

Overflow?

  • Yes
  • No

01101 · overflow: No

xC = 1100, top bit set, so as a signed constant it is −4. Subtracting is one negation then an add: −(−4) = +4 = 00100. 01001 + 00100 = 01101 = 13. Positive + positive gave positive: no overflow. Trap: negating and then subtracting again (gives 00101).

Back to the problems