ITPEC FE Morning April 2019 Question 1

For an eight-bit integer x represented in two’s complement format, which of the following yields the value of 5x? Here, the overflow or underflow can be ignored in this multiplication.

Explanation

Shift 2 bits to the left, then add the original value — 5x = 4x + x, and a 2-bit left shift multiplies by 4.

In two's complement, a left shift by k bits multiplies by 2k and an arithmetic right shift by k bits divides by 2k, keeping the sign.

  • •Write 5 as a power of two plus a small term: 5 = 4 + 1 = 22 + 1
  • •Shift x 2 bits to the left: 4x
  • •Add x: 4x + x = 5x

Answer (b)

Why not others:

  • •(a) — a 1-bit shift is only ×2, so the result is 2x + x = 3x
  • •(c) — a right shift divides instead of multiplying: x ÷ 2 − x = −x ÷ 2
  • •(d) — likewise x ÷ 4 − x = −3x ÷ 4, a fraction of x with the wrong sign

Key rule: To multiply by a constant with shifts, write it as a sum or difference of powers of two, such as 5 = 22 + 1 or 7 = 23 − 1, and use left shifts; right shifts divide.

Basic Theory · AI-written, may contain errors

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.