This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes shift question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "shift question" Watch "shift question" New topic

shift question


Joined: Feb 17, 2004
Posts: 3
hi all,
i do'nt know what differences between Sample1 & Sample2.
code 1:
class Sample1{
public static void main(String args[]){
int i=-1;
code 2:
class Sample2{
public static void main(String args[]){
int i=-1;
thank you!!
Igor Ko
Ranch Hand

Joined: Jun 24, 2002
Posts: 90
try it, it will help:

If the promoted type of the left-hand operand is int, only the five lowest-order bits of the right-hand operand are used as the shift distance. It is as if the right-hand operand were subjected to a bitwise logical AND operator & (�15.22.1) with the mask value 0x1f. The shift distance actually used is therefore always in the range 0 to 31, inclusive.

Java Language Specification.
So actually:
shfit -1 is shift to 31
shift -2 is shift to 30
shift -3 is shift to 29
shift -4 is shift to 28
. . . . . . . . . . . . .
[ March 15, 2004: Message edited by: Igor Ko ]
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: shift question
jQuery in Action, 3rd edition