Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
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 orders confusing

Ranch Hand
Posts: 31
• Number of slices to send:
Optional 'thank-you' note:
I found the operator oder is different between bit shift and bitwise:
what is the order for:
8 | 9 & 10 ^ 11
and what is:
int x= 8 >> 9 <<< 10 >> 11
and what is:
boolean y==true==false==true;
can anybody please explain to me?

Thanks.

Ranch Hand
Posts: 31
• Number of slices to send:
Optional 'thank-you' note:
Hi,
I can explain you reg.
boolean y==true==false==true;
It should be written as
boolean y=true==false==true; there should not be == after y
the evaluation is from right to left.
so y = true==false==true;
>> = true==(false==true);// bcoz false!=true therefore val of //expression is false
>> = true==(false);
>> = true==false; // here too val if exp is false;
>> = false;
therefore y = false
HTH
sasi

Originally posted by Michael Lin:
I found the operator oder is different between bit shift and bitwise:
what is the order for:
8 | 9 & 10 ^ 11
and what is:
int x= 8 >> 9 <<< 10 >> 11
and what is:
boolean y==true==false==true;
can anybody please explain to me?

Thanks.

sasi dhulipala
Ranch Hand
Posts: 31
• Number of slices to send:
Optional 'thank-you' note:
Hi,
once again reg int x= 8 >> 9 <<< 10 >> 11;<br /> the left shift operator is << not <<< <br /> so the expression should be <br /> int x = 8 >> 9 << 10 >> 11;<br /> evaluating from Right to left<br /> x = 8 >> 9 << 10 >> 11;<br /> = 8 >> 9 << (10 >> 11);
= 8 >> 9 << ( 0); //bcoz 10 >> 11 = 0;
= 8 >>( 9 << 0);<br /> = 8 >> 9; //bcoz 9 << 0 = 9;
= 0;
there fore 0 is printed;
HTH
sasi
[This message has been edited by sasi dhulipala (edited January 04, 2001).]

Ranch Hand
Posts: 39
• Number of slices to send:
Optional 'thank-you' note:
in both the cases the evaluation should be from left to right.
though, in these cases the direction of evaluation doesnt effect the fine result.
-Aj

Ranch Hand
Posts: 133
• Number of slices to send:
Optional 'thank-you' note:
int x= 8 | 9 & 10 ^ 11; yeilds 11. Because the operator precedence in decending order is: &,^,| and =; To remember the precedence order of &, ^, |, just bear in mind the order is the same as from the most strict to the least strict.

Ranch Hand
Posts: 142
• Number of slices to send:
Optional 'thank-you' note:
BUT the order of assocoativity for shift operators is left 23 right so doesn't it mean that it has to be evaluated from left to right rather then right 2 left which has been done above
PLz clarify i am confused
------------------
"Winners don't do different things
They do things differently"

Ranch Hand
Posts: 81
• Number of slices to send:
Optional 'thank-you' note:
i think >> >>> and << operator goes form left to right ..
anyway here is the test for that
int a = Integer.MAX_VALUE;
System.out.println(a<<1>>1); //-1
System.out.println(a<<(1>>1)); //21......
System.out.println((a<<1)>>1); //-1
hope this will clear the doubts....

Tom Tang
Ranch Hand
Posts: 133
• Number of slices to send:
Optional 'thank-you' note:
The precedence of shift operator is in decreasing order as "<<,>>,>>>".

anil bisht
Ranch Hand
Posts: 81
• Number of slices to send:
Optional 'thank-you' note:
hi Tom
there is no precendence for shift operators...
System.out.println(a>>32<<2);//-4<br /> System.out.println((a>>32)<<2);//-4<br /> System.out.println(a>>(32<<1));//-1
so i think it works left to right

Ajay Patel
Ranch Hand
Posts: 39
• Number of slices to send:
Optional 'thank-you' note:
lets lay the argument to rest.
- all the shift operators have the same precedence, and
- assocoativity is left to right for shift operators.
i think Anil's examples are great and should clarify everyone's doubts.
-Aj

 Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters?