Question

Let XX be the number of distinct 16-bit integers in 2's complement representation. Let YY be the number of distinct 16-bit integers in sign magnitude representation.

Then X−YX - Y is ________.

Official answer and solution
Official answer
1
From
Official GATE 2016 answer key

Solution

Count the number of distinct integers representable in 16-bit 2's complement and sign-magnitude representations.

  1. 16-bit 2's complement representation:
  • The range of representable integers is [−215,215−1]=[−32768,32767][-2^{15}, 2^{15} - 1] = [-32768, 32767].
  • In 2's complement, every bit pattern represents a unique integer (zero has a single representation 0000…00000\dots0).
  • Number of distinct integers: X=216=65536X = 2^{16} = 65536.
  1. 16-bit sign-magnitude representation:
  • The range of representable integers is [−(215−1),215−1]=[−32767,32767][-(2^{15} - 1), 2^{15} - 1] = [-32767, 32767].
  • Zero has two representations: +0+0 (0000…00000\dots0) and −0-0 (1000…01000\dots0).
  • Number of distinct integers: Y=216−1=65535Y = 2^{16} - 1 = 65535.
  1. Calculate the difference:
X−Y=65536−65535=1X - Y = 65536 - 65535 = 1

Thus, X−Y=1X - Y = 1.

Final answer

1

Common trap

Thinking sign-magnitude has 2 fewer numbers instead of 1 (due to the single redundant representation of zero).

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2016 Computer Science and Information Technology (CS) Session 2
Question
19 of 65, printed as CS Q.9
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.