Results 1 to 9 of 9
Thread: Operators Problem
- 12-25-2012, 08:44 PM #1
Member
- Join Date
- Dec 2012
- Posts
- 4
- Rep Power
- 0
Operators Problem
I have some experience in many programming languages,and I decided to learn Java...But,it has some new operators that i didn't see at other programming languages before...
For example, the operators: "~","^","|","&".What does everyone mean??
And,I'm not sure with the operators: >>,<<,>>>,<<<...I know what they do..But how do they help me???
Thanks.
- 12-25-2012, 09:02 PM #2
Re: Operators Problem
Those are bitwise operators.
Have a read about them here: Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)
- 12-25-2012, 09:13 PM #3
Member
- Join Date
- Dec 2012
- Posts
- 4
- Rep Power
- 0
Re: Operators Problem
But how can they help me? (-.-) And,please explain a little bit better...I don't understand many on that site.
- 12-25-2012, 09:24 PM #4
Member
- Join Date
- Dec 2012
- Posts
- 4
- Rep Power
- 0
Re: Operators Problem
When should i use these operators?? how do they help?
-
Re: Operators Problem
As PHQ stated, they are bit-wise operators and are based on their C-programming language equivalents (except for the >>> and <<< as far as I know), and so they are quite commonly used in many programming languages.
Rather than have us re-write a tutorial, perhaps you can tell us what specifically about the tutorial on the site linked to by PHQ confuses you.
Much luck with your Java studies!
- 12-25-2012, 11:39 PM #6
Member
- Join Date
- Dec 2012
- Posts
- 4
- Rep Power
- 0
Re: Operators Problem
But when should I use them??
-
Re: Operators Problem
Myself, I don't use them often, but I have used them when I needed to do bit manipulations when working with color bitmaps. A color may be represented as an int with the opacity in the highest order bit, the amount of red in the next order bit, the green in the next order bit, and the blue in the last bit. If you want to extract these pieces of information from the int, you may need to use these operators. I also use them when working with flags -- ints where each bit can be turned on or off and represents a piece of information. For instance when doing Swing coding and when using a MouseListener, the mouse data can be passed to my program from Java in the MouseEvent object via two ints, the modifiers int and the modifiersEx int, and each bit in the int tells me the state of the mouse (which button is involved, if the button was pressed or released) and also whether alt, ctrl, or shift have been pressed.
There are many other uses for them, and if you code with Java, you will run into this, I can assure you, so they are very useful to learn.
- 12-25-2012, 11:58 PM #8
Re: Operators Problem
Best way to learn how they work is by experimenting with them, once you test a few values you will start to see some patterns.
For example
16 << 0 prints out 16,
16 << 1 prints out 32,
16 << 2 prints out 64,
16 << 3 prints out 128Last edited by PhQ; 12-26-2012 at 12:06 AM.
- 12-26-2012, 09:40 AM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
Re: Operators Problem
Just a nasty nitpick: there exists no <<< operator; a logical left-shift operator would equal an arithmetic left-shift (<<) b.t.w. BCPL already had those bit-operators and C 'borrowed' them from BCPL. C doesn't need the distinction between logical/arithmetic shift-right because it has unsigned ints. I still wonder why none of these languages have a 'rotate' operator ...
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
operators (/,*,+,-)
By user07 in forum New To JavaReplies: 7Last Post: 09-03-2012, 09:36 PM -
string operators
By cagipple in forum New To JavaReplies: 5Last Post: 04-17-2011, 01:04 AM -
New to operators, need some help...
By Stryker4526 in forum New To JavaReplies: 4Last Post: 09-26-2009, 01:29 AM -
Java Operators
By Ash-infinity in forum New To JavaReplies: 6Last Post: 12-02-2008, 11:51 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks