Win a copy of Spring in Action (5th edition) this week in the Spring 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
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Operators '>>=' and '<<='  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi people,


I have known java for several years now..
a friend came to me yesterday and she asked if I can explain following operators:
I did do  some research on them but I still doesn't understands them.

>>=
<<=

w3 schools

Can someone explain these in a very newbie-friendly way since I am not much into math.

Many thanks in advance

Regards

XsiSec
 
Rancher
Posts: 502
11
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They're called bitshift operators. Here's a link

By the way...
w3schools is great when it comes to front-end, but I would never go there for something java related.
The JavaDocs should always be your first place to go.
 
Marshal
Posts: 61715
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You have been unlucky in your choice of tutorial; that site gave no explanation of the operator, only showing that 5 >> 3 comes to 0. And that tutorial gets even worse further down We ought to have a list of bad internet tutorials so we can add that one to it.
Let's to the JLS (=Java® Language Specification) where you find that is a compound assignment operator, made up of the ordinary right‑shift operator >> and the assignment operator joined together. That's really helpful isn't it? The JLS section lets you work out thatis equivalent to...where (type) is a cast to whatever the original type of i was. So, if i started off life as an int, it is implicitly cast back to an int. The right operand should usually be an int between the values of 0...31 (0...63 if left operand is a long/Long). If the right operand is outwith that range, its 5 or 6 rightmost bits only are used, so it comes back into that range. The left operand can be any integer primitive or a Long or an Integer via unboxing and boxing. The >> operator takes the bit pattern of the left operand j bits to the right (0 ⩽ j ⩽ 31 for an int), and that is equivalent to dividing by 2 j×. The leftmost bits are filled up by whatever the original bit₃₁ was, so negative numbers remain negative.
There is a discussion of bitwise operators on the Ranch, in the JLS and in the Java™ Tutorials. Needless to say, the CodeRanch link is the best The links will also tell you what << and >>>, hence <<= and >>>=, do.
 
Daniel Demesmaecker
Rancher
Posts: 502
11
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Welcome to the Ranch

You have been unlucky in your choice of tutorial; that site gave no explanation of the operator, only showing that 5 >> 3 comes to 0. And that tutorial gets even worse further down We ought to have a list of bad internet tutorials so we can add that one to it.



I guess that was directed at me? Sorry.. I will be less lazy next time and actually check what I googled lol
On your last remark, I don't actually think that idea is half bad
 
Campbell Ritchie
Marshal
Posts: 61715
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:. . . I guess that was directed at me? Sorry.. . . .

No, it wasn't. I agree with your opinion of w3schools. There is nothing to apologise for. I didn't realise you had posted when I wrote that, so maybe I should apologise.
 
Campbell Ritchie
Marshal
Posts: 61715
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:. . . On your last remark, I don't actually think that idea is half bad

Would you like to compile a list of tutorials? Be careful not to do it too well, or we might kidnap you as a mod (mwaahaahaahaahaahaahaahaahaa!)
 
Daniel Demesmaecker
Rancher
Posts: 502
11
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Would you like to compile a list of tutorials? Be careful not to do it too well, or we might kidnap you as a mod (mwaahaahaahaahaahaahaahaahaa!)


On that remark I'm hesitant to do so, I don't want to seem to eager to become a mod so... but it might still be helpfull, where would be a good place to do so? Wiki?
 
Something about .... going for a swim. With this tiny ad ...
Download Free Java APIs to Work with Office Files and PDF
htttp://www.e-iceblue.com/free-apis.html
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!