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.

I assume that you know what the >> operator do. In fact if the right hand side operator is 32, it just do nothing. The explanation come from the modulo. 32 modulo 32 =0 so do nothing. 32 modulo 31 =31 so do 31 32 modulo 33 =1 so do 1. So if you do int >> 33 or int >>1 it just do the same thing. I hope my explanation is helpfull!!! If not,do not hesitate to contact me. Sorry for my english

Younes
By constantly trying one ends up succeeding. Thus: the more one fails the more one has a chance to succeed.

Younes Essouabni
Ranch Hand

Joined: Jan 13, 2002
Posts: 479

posted

0

It's just the wrong it's 32 modulo 32=0 33 modulo 32=1 31 modulo 32=31

System.out.println(32>>32);//case1 the result show : 32 System.out.println(32>>31);//case2 the result show : 0

For shift operators, 'only the five lowest-order bits of the right-hand operand are used as the shift distance, if the left-hand operand is int'. In case1, the 5 bits are: 00000. So, the left-hand operand (32) gets shifted by 0 bits and hence the result is the same: 32. In case2, the 5 bits are: 11111. So, the left-hand operand (32) gets shifted by 31 bits and hence the result is: 0.

I see that your are new to this forum. Plz do a search for your question before you post. This has been discussed many times before.

Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.<br />- Dr. Seuss