in Digital Logic retagged by
13,458 views
19 votes
19 votes

Consider $Z=X-Y$ where $X, Y$ and Z are all in sign-magnitude form. X and Y are each represented in $n$ bits. To avoid overflow, the representation of $Z$ would require a minimum of:

  1. $n$ bits
  2. $n-1$ bits
  3. $n+1$ bits
  4. $n+2$ bits
in Digital Logic retagged by
by
13.5k views

5 Answers

55 votes
55 votes
Best answer
Let $X$ and $Y$ represents $31$ and $- 31$ respectively in binary sign magnitude form. $X$ and $Y$ will take $6$ bits as range of sign magnitude form is $-\left(2^{(n-1)}-1\right)$ to $2^{(n-1)}-1$; where $n$ is the number of bits.

Now in question $Z= X-Y$,

$Z = 31 - (-31) = 62$

To represent $62$ in sign magnitude form we need $7\;( 6+1)$ bits.

Hence, $n+1$ bits needed.

Answer is $C$.
edited by

4 Comments

is it the same for 2’s complement also?
0
0
Would not Z require an additional bit for the sign...for a total of (n+1)+1 bits? so i thought answer would be N+2 bits
0
0

@Gopal Deshmuk Don’t forget the basics. In sign magnitude representation, if n bits are used for representation then out of n bits, 1 bit (MSB) represents sign and (n-1) bits will denote magnitude.

So, while doing any operation (Addition, Subtraction, Multiplication, etc.) on n bit values, the magnitude may overflow i.e., it may require one more bit than normally. Hence to avoid overflow magnitude will be given one more bit than usual i.e., $(n-1)+1 = n$ bits and 1 bit will be required for sign representation. 

Thus, total bits required = ${\color{Red} ((n-1)+1 )} + {\color{DarkBlue} 1}$ $= {\color{Magenta} (n+1)}$ bits

3
3
15 votes
15 votes
No overflow if two number with opposite sign are added.
Here $(X+(-Y))$ wont give any overflow if sign of $X$ and $-Y$ are opposite else it may cause overflow.
Nothing mentioned in question so in worst case it will give overflow.

Additional bit needed to handle overflow.
Total $n+1$ bits needed.
edited by
7 votes
7 votes

Overflow can occur when two same sign numbers are added or two opposite sign numbers are subtracted. For example:

let n = 4 bit, X = +6 and Y = -5 (1 bit for sign and 3 bit for magnitude)
Therefore, Z = X - Y = 6 - (-5) = 6+5 = 11
But result (Z) 11 needs 5 (= 4 + 1) bits to store, 
Sin integer 11 needs 1 bit for sign and 4 bit for magnitude. 

Therefore, to avoid overflow, the representation of Z would require a minimum of (n + 1)bits. Option (C) is correct.

 

https://www.geeksforgeeks.org/gate-cs-2019/

1 vote
1 vote
n+1

ans (C)
Answer:

Related questions