# UGCNET-june2007-12

3 votes
564 views
In case of right shift bitwise operator in ‘C’ language, after shifting n bits, the left most n bits:
(A) are always filled with zeroes
(B) are always filled with ones
(C) are filled with zeroes or ones and is machine dependent
(D) none of the above

0

The right-shift operator causes the bit pattern in shift-expression to be shifted to the right by the number of positions specified by additive-expression. For unsigned numbers, the bit positions that have been vacated by the shift operation are zero-filled. For signed numbers, the sign bit is used to fill the vacated bit positions. In other words, if the number is positive, 0 is used, and if the number is negative, 1 is used.

https://msdn.microsoft.com/en-us/library/336xbhcz.aspx

## 1 Answer

0 votes
For example if we consider 2 it's binary equivalent is 010

If we perform right shift of one bit it will become 001

So left most n bits are filled with zero's
0

but if we consider -2, then left most n bits are filled with one's

0
then it should be can be filled with one's or zero's depending on the number whether it is signed or unsigned
0
so what is the correct ans now ?
0
The answer is ambigious as in the question they didnot mention whether it is signed  or unsigned answer should be none of the above.
0
but according to given option, i think option C is appropriate... what u think regarding this ?
0
machine dependent??? value will be same for all the machines it depends on the number whether it is signed or unsigned and accordingly will be filled with zero's or one's.
0
In C programming we use 2's Complement, So going with the options 'd' is best suited. As 'a' and 'b' both are true for positive and negative numbers respectively. 'c' is also not correct as Complementation used is not dependent on Machine and C use 2's complement.

So ans should be 'd'.
0

and if option C is like this only "are filled with zeroes or ones"   then we can go for option C, i mean according to you guys option C is wrong bcz of "machine dependent"

0

I think "are filled with zeroes or ones" would also contains the case where both can come simultaneously like (0 + 1)* (if want to explain in terms of R.E.) .

More specific answer would be 0's for positive and 1's for Negative.

0

plzz have a look on this--> https://stackoverflow.com/questions/4009885/arithmetic-bit-shift-on-a-signed-integer

acc to it.. ans C is more appropriate...what u think..?

0
Yes, C option is more appropriate. And thanks for providing this link.
Answer:

## Related questions

0 votes
1 answer
1
51 views
In case of right shift bitwise operator in $’C’$ language, after shifting $n$ bits, the leftmost $n$ bits: are always filled with zeros are always filled with ones are filled with zeros or ones and is machine dependent none of the above
2 votes
1 answer
2
73 views
What is the output of the following $\text{’C’}$ program? main() { printf(“%x”,-1>>4); } $\text{ffff}$ $\text{0fff}$ $\text{0000}$ $\text{fff0}$
1 vote
1 answer
3
703 views
The following loop in ‘C’: int i=0; While(i++<0)i--; (A) will terminate (B) will go into an infinite loop (C) will give compilation error (D) will never be executed
1 vote
1 answer
4
62 views
The following determiniotic finite automata recognizes: Set of all strings containing $’ab’$ Set of all strings containing $’aab’$ Set of all strings ending in $’abab’$ None of the above