doubt

10 views
Skip to first unread message

Aashish

unread,
Mar 15, 2011, 2:12:33 PM3/15/11
to Coders in NIT Durgapur
can anyone tell that why the value of ~0 is -1 and ~4 is -5?
and why right shift is not making any change in (~0)>>1....

anoop chaurasiya

unread,
Mar 16, 2011, 12:51:51 AM3/16/11
to nitdc...@googlegroups.com
let us use 8 bit numbers...
0=(00000000)2
~0=(11111111)2
1=(00000001)2
-1=2's complement of 1=(11111110+1)2=(11111111)2=~0
similarly ~4=-5,
>> is actually the arithmetic right shift operator(means rights shifting shifts the bit pattern to the right and extends the rightmost bit ie. if right most bit is 0, a 0 is produced on the left, if it is 1,a 1 is produced).
i think u need to google a bit to get the notion of 2's complement form and arithmetic right shifting.

On Tue, Mar 15, 2011 at 2:12 PM, Aashish <aashish...@gmail.com> wrote:
can anyone tell that why the value of ~0 is -1 and ~4 is -5?
and why right shift is not making any change in (~0)>>1....



--
Anoop Chaurasiya
CSE (2008-2012)
NIT DGP
Reply all
Reply to author
Forward
0 new messages