• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Operator precedence

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, everybody:
What is the eveluating order and results for these questions?
Pls expain it for me. Thanks.

----------------------------------------
int n = 7;
n<<=3;<br /> n = n & n + 1 | n + 2 ^ n + 3;<br /> n >>= 2;
System.out.println(n);
----------------------------------------
8 | 9 & 10 ^ 11
----------------------------------------
boolean b1=b2=b3=b4=true
b1 | b2 & b3 ^ b4
----------------------------------------
boolean b1=b2=b3=b4=true
b4 = b4 | b1 & b2;
b3 = b3 & b1 | b2;
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
int n = 7;
n<<=3;<br /> n = n & n + 1 | n + 2 ^ n + 3;<br /> n >>= 2;
System.out.println(n);
The order of execution for the bitwise and or and Xor operator is as follows first it evaluates the bitwise and(&) then it evaluates the bitwise Xor(^) ann then it evaluates the bitwise or(|)
but in the expression(n = n & n + 1 | n + 2 ^ n + 3 )) all the airthmetic operators will be evaluated first then the bitwise operators and finally the assignment took place.
so the result is 56.
8 | 9 & 10 ^ 11
result will be 14.
boolean b1=b2=b3=b4=true
b1 | b2 & b3 ^ b4
you can not do assignment and initialization at the same time.
rather you can say
boolean b1,b2,b3,b4;
b1=b2=b3=b4=true;
b1 | b2 & b3 ^ b4;
then result would be true.
& is first to be evaluated then ^ and then |
same resion for the following.
b4 = b4 | b1 & b2;
b3 = b3 & b1 | b2;
correct me if i am wrong.
Thanks.
[This message has been edited by Amit, Jhalani (edited January 12, 2001).]
[This message has been edited by Amit, Jhalani (edited January 12, 2001).]
 
We can fix it! We just need some baling wire, some WD-40, a bit of duct tape and this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic