Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

why -1>>>32 results in -1  RSS feed

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this value must be zero.But it outputs -1.

I think >>> operator cannt produce negative numbers.
can any one please explain me how this value is generated.

thanks in advance
 
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Section 15.19 of the Java Language Specification 3.0 explains why this is:

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.


So, no shifting is taking place here. The -1 returned is the original (unshifted) parameter.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is shifting operator is there in java 1.5 exam?
 
vijaya saradhi
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Ulf Dittmer !!!.

for your good guidance
 
Ulf Dittmer
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Is shifting operator is there in java 1.5 exam?


No.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
2.Any questions on high calculation for bit shifting? Like shifting the bits to x # so that resulting # is big, such questions can consume large amount of time in calculation!!

3.Can SUN have Any questions on AWT, in SCJP1.4?
 
RashMin Gadhavi
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.Any questions on high calculation for bit shifting? Like shifting the bits to x # so that resulting # is big, such questions can consume large amount of time in calculation!!

2.Can SUN have Any questions on AWT, in SCJP1.4?
 
Ulf Dittmer
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All these questions about what is and isn't in the exam are answered by the exam objectives, which you should study thoroughly before starting to learn.
 
A timing clock, fuse wire, high explosives and a tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!