• 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Operator: & ^ |  RSS feed

 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahh...the order of precendence. Got it. Thanks!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!