In both C and C++, the result of a right shift of a signed value is
implementation specific. The vacated bits can be filled either with
zeros or with copies of the sign bit. Portable code must not depend on
the implementation, but must work with either implementation choice.

Thus, the result could be ffff if the vacated bit is filled with a
copy of the sign bit, or it could be 7fff if the vacated bit is filled
with zero.

The original poster's option [B] 0fff is not possible, because it
represents a right shift of four bits (with zero fill) rather than a
right shift of one bit.

The correct answer, according to the language standards, therefore, is
[E] None of the above.

Dave

On Aug 8, 11:07 am, navin <navin.myhr...@gmail.com> wrote:
> Assunming, integer is 2 byte, What will be the output of the program?
>
> #include<stdio.h>
>
> int main()
> {
>     printf("%x\n", -1>>1);
>     return 0;
>
> }
>
> [A].    ffff
> [B].    0fff
> [C].    0000
> [D].    fff0
>
> Answer: Option A
>
> i dont understand why it produces ffff
> actually -1  = ffff
> there shoud be one bit zero ( ie msb. )
> pls explain anyone.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to