Re: [algogeeks] Re: bitwise operator confusion

2010-08-09 Thread Mihai Donțu
On Monday 09 August 2010 13:22:20 Avik Mitra wrote: > ANSI standard specifies that during right shift of a negative number > the shift MUST be a logical shift with sign extension. So, > when right shifted will logically with sign extention it > gives (in hex). > So the answ

Re: [algogeeks] Re: bitwise operator confusion

2010-08-09 Thread VENKATARAMAN.GB
#include int main() { printf("%x\n", (unsigned)-1>>1); return 0; } this will give you the expected result. Cheers, venki VENKATARAMAN.GB "If Its Upto Be, It Is Upto Me" On Mon, Aug 9, 2010 at 3:53 PM, Avik Mitra wrote: > > Note that (in hex) is 2's compleme

[algogeeks] Re: bitwise operator confusion

2010-08-09 Thread Avik Mitra
Note that (in hex) is 2's complement representation of -1. -- 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+unsubs

[algogeeks] Re: bitwise operator confusion

2010-08-09 Thread Avik Mitra
ANSI standard specifies that during right shift of a negative number the shift MUST be a logical shift with sign extension. So, when right shifted will logically with sign extention it gives (in hex). So the answer is [A]. -- You received this message because you are subs

[algogeeks] Re: bitwise operator confusion

2010-08-08 Thread Dave
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