Machine-translated by Google. Questions are authored in English.
Top

Discussion

Consider a system that uses 5 bits for representing signed integers in 2’s complement format. In this system, two integers \(A\) and \(B\) are represented as \(A\)=01010 and \(B\)=11010. Which one of the following operations will result in either an arithmetic overflow or an arithmetic underflow?

  • A.\(A + B\)
  • B.\(A - B\)
  • C.\(B - A\)
  • D.\(2 * B\)

Answer: B

The operation that overflows is \(A - B\).

Five-bit two's complement represents −16 to +15. A = 01010 = +10, and B = 11010 = 26 − 32 = −6. Then:

  • A + B = 10 − 6 = 4: in range
  • A − B = 10 + 6 = 16: above +15, overflow
  • B − A = −6 − 10 = −16: exactly the most negative value, in range
  • 2 * B = −12: in range

So only A − B leaves the representable range. The trap is B − A: −16 looks extreme but is representable as 10000, because two's complement has one more negative value than positive.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.