This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Shift operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Shift operator" Watch "Shift operator" New topic

Shift operator

Sridhar Srinivasan
Ranch Hand

Joined: Nov 07, 2003
Posts: 117
How to find the value of 0xffffffff>>1 Can anybody help pl!Thanks
[ May 23, 2004: Message edited by: Barry Gaunt ]

meeta verma

Joined: May 15, 2004
Posts: 19
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
I agree. Here's the link:
subject: Shift operator
Similar Threads
Insert a 7k String into Oracle CLOB?
Inherting from JApplet
help again
Bitwise operations with Enumerated types
prob with weblogic 5.1