This week's book giveaways are in the AI and JavaScript forums.
We're giving away four copies each of GANs in Action and WebAssembly in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

what is the value of 8 | 9 & 10 ^ 11 ?

 
Trailboss
Posts: 23079
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are we really going to get a question like this? IOW-- do we really have to memorize the precedence of the bitwise operators?
 
paul wheaton
Trailboss
Posts: 23079
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what is the answer to this anyway? I don't have a reference handy for this kind of thing and left to right isn't giving me one of the answers provided (8, 9, 10 or 11).
 
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, my guess is
<pre>
8 | ((9 & 10) ^ 11)
=> 1000 | ((1001 & 1010) ^ 1011)
=> 1000 | ( 1000 ^ 1011 )
=> 1000 | 0011
=> 1011
=> 11
</pre>
Is this right?
 
paul wheaton
Trailboss
Posts: 23079
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a reference book now, but it shows the bitwise operators all in the same precedence, so from that I would guess that left to right would apply....
I loaded the expression into a test program. Compile and run... The answer is 11 - you were right.
The real question is: Do we need to know this level of precedence for the SCJP2 exam?
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know which "reference" book you have, but I use Java in a Nutshell (2ed) from O'Reilly which correctly lists the precedence of all the operators on pages 228 and 229.
And no, I don't think you really need to know it in that much detail. Especially as you can afford to lose a few points and still pass.
 
paul wheaton
Trailboss
Posts: 23079
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm wanting to get a high score. I'm certain I could have passed the test weeks ago. But it's those last few percentage points I want to reduce.
So - this sort of stuff WILL be on the test. Right?
I have the Java in a nutshell book - thanks for the info. I'll have to try to memorize this stuff I guess.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i post this from jls 15.21 for operator precedence for & , ^ and |.
These operators have different precedence, with & having the highest precedence and | the lowest precedence. Each of these operators is syntactically left-associative (each groups left-to-right).
[This message has been edited by rahul_mkar (edited May 04, 2000).]
 
Ranch Hand
Posts: 289
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My friend, you really need any point that comes your way, and you can not afford to lose apoint when you dont know what the next question brings. You DO have to know the operator precedence because it accounts to answering so many questions. Moreover, you need to know it to be a real programmer.
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made up a mneomonic (im sure i spelled that wrong!) for the operator precedence
"you ask bullshit then assign"
U - Unary
A - Arithmetic
S - Shift
C - (mneumonic licence) Comparison
B - Bitwise
S - Shortcut
T - Ternary
A - Assign
Works out to U ASC BullShit Then Assign
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Nalini Mistry
could u please provide us with an example to clarify and end this thread
 
Rancher
Posts: 241
Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the mnemonic, I like it.
Eric
 
The harder I work, the luckier I get. -Sam Goldwyn So tiny. - this ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!