It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Shift by -ve value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Shift by -ve value" Watch "Shift by -ve value" New topic

Shift by -ve value

geetha nagarajan
Ranch Hand

Joined: Jul 13, 2001
Posts: 94
Why is the shift operation by a -ve value ,not a compiler error.(eg: 12 >> -2)?
It compiles fine and gives 0 as o/p.
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Doing a shift by a negative number is not a compiler error. It is a legal operation in Java. Do a search in this forum as this topic has been discussed many times.

SCJP Tipline, etc.
I agree. Here's the link:
subject: Shift by -ve value
jQuery in Action, 3rd edition