Question

Consider Z=X−YZ = X - Y, where X,YX, Y and ZZ are all in sign-magnitude form. XX and YY are each represented in nn bits. To avoid overflow, the representation of ZZ would require a minimum of:

Choose one option
Official answer and solution
Official answer
C
From
Official GATE 2019 answer key

Solution

Find the range of values of the difference Z = X - Y in sign-magnitude representation and determine the minimum number of bits needed to represent it without overflow.

In an nn-bit sign-magnitude representation, 11 bit is used for the sign and n−1n-1 bits are used for the magnitude. The range of representable numbers is:

−[2n−1−1,2n−1−1]-[2^{n-1} - 1, 2^{n-1} - 1]

Let X,Y∈[−(2n−1−1),2n−1−1]X, Y \in [-(2^{n-1} - 1), 2^{n-1} - 1]. The maximum possible value of Z=X−YZ = X - Y occurs when X=2n−1−1X = 2^{n-1} - 1 and Y=−(2n−1−1)Y = -(2^{n-1} - 1):

Zmax⁡=(2n−1−1)−(−(2n−1−1))=2(2n−1−1)=2n−2Z_{\max} = (2^{n-1} - 1) - (-(2^{n-1} - 1)) = 2(2^{n-1} - 1) = 2^n - 2

Similarly, the minimum possible value is:

Zmin⁡=−(2n−1−1)−(2n−1−1)=−(2n−2)Z_{\min} = -(2^{n-1} - 1) - (2^{n-1} - 1) = -(2^n - 2)

To represent a magnitude as large as 2n−22^n - 2 in sign-magnitude form:

2m−1≥2n−2  ⟹  2m>2n−1  ⟹  m≥n2^m - 1 \ge 2^n - 2 \implies 2^m > 2^n - 1 \implies m \ge n

Thus, the magnitude requires at least nn bits. Adding 11 bit for the sign gives a total of n+1n + 1 bits.

Final answer

C

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

Source

Paper
GATE 2019 Computer Science and Information Technology (CS)
Question
18 of 65, printed as CS Q.8
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.