File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes pls tell me why? 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 "pls tell me why?" Watch "pls tell me why?" New topic
Author

pls tell me why?

qunlbao leon
Greenhorn

Joined: Jan 16, 2002
Posts: 7
System.out.println(32>>32);
the result show : 32
System.out.println(32>>31);
the result show : 0
why? I only know the result from 32>>5 to 32>>0
Younes Essouabni
Ranch Hand

Joined: Jan 13, 2002
Posts: 479
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
It's just the wrong
it's 32 modulo 32=0
33 modulo 32=1
31 modulo 32=31
Raghav Sam
Ranch Hand

Joined: Apr 12, 2001
Posts: 412
Hi,

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: pls tell me why?