Skip to main content
Logo image

Dive Into Systems: Exercises

Section 4.5 Overflow

Checkpoint 4.5.1. Overflow.

Imagine that you are on an alien planet where one day is 8 hours long. If you look at a clock on this planet and see that it is 6 o’clock, what time will it be in 5 hours?
o’clock.
Hint.
Draw out the 8-hour clock and walk through the addition of each hour starting at 6.

Checkpoint 4.5.2. Carry Out vs. Overflow.

    When adding a positive and a negative number, which of the following is true:
  • There is never overflow
  • Correct!
  • There is always overflow.
  • Incorrect.
  • There may or may not be overflow.
  • Incorrect.

Checkpoint 4.5.3. Modular Arithmetic and Binary Addition.

    Given any two 8-bit unsigned values A and B, which of the following expressions represents the 8-bit result value of adding \(A+B\text{?}\)
  • \((A + B) \% 2^8\)
  • Correct!
  • \(A + B\)
  • Incorrect.
  • \((A + B) / 8\)
  • Incorrect.
  • \((A + B) // 2^8\)
  • Incorrect.
  • None of these options
  • Incorrect.

Checkpoint 4.5.4. Overflow in Two’s Complement Addition.

    When adding two 4-bit two’s complement values, there is overflow if:
  • the operands are 0xxx and 0xxx, and the result is 1xxx.
  • Correct!
  • the operands are 0xxx and 0xxx, and the result is 0xxx.
  • Incorrect.
  • the operands are 0xxx and 1xxx, and the result is 1xxx.
  • Incorrect.
  • the operands are 0xxx and 1xxx, and the result is 0xxx.
  • Incorrect.
  • the operands are 1xxx and 1xxx, and the result is 0xxx.
  • Correct!
  • the operands are 1xxx and 1xxx, and the result is 1xxx.
  • Incorrect.

Checkpoint 4.5.5. Overflow in Two’s Complement Subtraction.

    When subtracting two 4-bit two’s complement values, there is overflow if:
  • the calculation is 0xxx - 1xxx and the result is 1xxx.
  • Correct!
  • the calculation is 0xxx - 0xxx and the result is 1xxx.
  • Incorrect.
  • the calculation is 0xxx - 0xxx, and the result is 0xxx.
  • Incorrect.
  • the calculation is 0xxx - 1xxx and the result is 0xxx.
  • Incorrect.
  • the calculation is 1xxx - 0xxx and the result is 0xxx.
  • Correct!
  • the calculation is 1xxx - 0xxx and the result is 1xxx.
  • Incorrect.
  • the calculation is 1xxx - 1xxx and the result is 0xxx.
  • Incorrect.
  • the calculation is 1xxx - 1xxx and the result is 1xxx.
  • Incorrect.

Checkpoint 4.5.6. Unsigned Overflow.

    Will adding 7 and 5 together result in an overflow when using 4-bit unsigned binary representations?
  • No
  • Correct!
  • Yes
  • Incorrect.

Checkpoint 4.5.7. Signed Overflow.

    Will adding 7 and 5 together result in an overflow when using 4-bit signed binary representations?
  • Yes
  • Correct!
  • No
  • Incorrect.

Checkpoint 4.5.8. Unsigned Overflow.

    For which unsigned arithmetic operation will having a carry out result in an overflow?
  • Addition
  • Correct!
  • Subtraction
  • Incorrect.
  • Both A and B
  • Incorrect.
  • Neither A nor B
  • Incorrect.

Checkpoint 4.5.9. Signed Overflow.

    Given two N-bit two’s complement numbers, X and Y, where both have the same value for the most significant bit, which of the following statements are true?
  • Performing X+Y will sometimes lead to an overflow.
  • Correct!
  • Performing X-Y will never lead to an overflow.
  • Correct!
  • Performing X+Y will always lead to an overflow.
  • Incorrect.
  • Performing X+Y will never lead to an overflow.
  • Incorrect.
  • Performing X-Y will always lead to an overflow.
  • Incorrect.
  • Performing X-Y will sometimes lead to an overflow.
  • Incorrect.

Checkpoint 4.5.10. Signed Overflow.

    When adding two N-bit two’s complement numbers, X and Y, in which of the following scenarios might there be an overflow?. Select ALL that apply.
  • X and Y are both positive.
  • Correct!
  • X and Y are both negative.
  • Correct!
  • X is positive, Y is negative.
  • Incorrect.
  • X is negative, Y is positive.
  • Incorrect.