File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Operator:  & ^ | Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Operator:  & ^ |" Watch "Operator:  & ^ |" New topic
Author

Operator: & ^ |

Shannon Sims
Ranch Hand

Joined: Jul 03, 2003
Posts: 197
I'm confused!!! I have compiled this code and I don't get the same results manually. Can someone please explain the following:
n = 7;
n = n & n + 1 | n + 2 ^ n + 3;
n = 57;
Here's how I'm figuring this out:
n = 7;
n = ( n & n ) + ( 1 | n ) + ( 2 ^ n ) + 3;
n = 56 + 57 + 58 + 3;
n = 174;
So, why isn't this right?
Thanks for the help!
Maverick Lasa
Greenhorn

Joined: Oct 18, 2003
Posts: 23
Originally posted by Shannon Sims:

n = 7;
n = n & n + 1 | n + 2 ^ n + 3;

this will be executed as:

refer to Java Expressions
mavedrive;
Shannon Sims
Ranch Hand

Joined: Jul 03, 2003
Posts: 197
Ahh...the order of precendence. Got it. Thanks!
 
wood burning stoves
 
subject: Operator: & ^ |
 
Similar Threads
Implementing recursive relations
assignment with & ...
A So Strange question !!(scjp07-Q108)
Is there an easy way to remember the operatos precedence?
Fibonacci Sum