Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Shift operator

 
Sridhar Srinivasan
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
How to find the value of 0xffffffff>>1 Can anybody help pl!Thanks
[ May 23, 2004: Message edited by: Barry Gaunt ]
 
meeta verma
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
0xffffffff = 1111 1111 1111 1111 1111 1111 1111 1111
since, the sight bit is one it represents a negative number.

Now 0xffffffff >> 1, i.e. signed right shift
0xffffffff >> 1 = 1111 1111 1111 1111 1111 1111 1111 1111 (u get same as previous) i.e. shift 1 bit to the right and add 1 as the most significant bit. We add one becoz we know that this number is negative (signed right shift of a negative num is always negative).
Now find the decimal of this negative num i.e. take 2's complement which will be 0000 0000 0000 0000 0000 0000 0000 0000 and add 1 and remember to put a negative sign.
So the result is -1
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic