This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Shift operators

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I find shift operators hard to understand. Can someone tell me what they would be used for? Thanks Col.
 
Trailboss
Posts: 22973
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm moving this thread to the forum "Java in General (beginner)"
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shift operators are basically used to shift the bits either to the right or left. doing so the number can be either be multiplited or divided by 2. the computers in the low level follow shifting of bits for multiplication or division.

------------------
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that shift operators are used alot in embedded systems (micro java for chips like for cars and your programmable thermostat etc.), where every bit and byte has to be optimized for space. You can do math (one shift left is the same as multiplying by 2) and maintain switches and all sorts of clever stuff with bitwise operators with little overhead in ram.
 
Colin Clark
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help.
 
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shift operators could also be used in situations where speed is critical. << 3 is faster than * 8 (Shifting left 3 is faster than mulitplying by 8). I've never seen this done, and it sure would be hard to read without thorough documentation, but it's been explained to me in concept. Does anyone really do this?
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've done it in C but never in Java.
Nick
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!