Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!