• 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

Shift operator

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i find this question from mock exam.
what is the output displayed by the following programe?
[CODE]
class Question{
public static void main(String args[]){
int n = 7;
n <<= 3;<br /> n = n & n+1 | n+2 ^ n+3 ;<br /> n >>= 2;
System.out.println(n);
}
}
can any one suggest fast way to calculate 'n' value.
I think this type of questions will take more time in exame. Is it possible to get this type questions in real exame.
Regards
Satish


 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Satishind,
First, I can't believe we will have a so complex question at the exam (I'm attending it on Thursday) because operators precedence are difficult to memorise properly. It is always advised to use parentheses to make a code more explicit to the reader.
Anyway, the easiest way to work out the results of binary operations is to express the result in binary form.

Please tell me if this is still unclear.
Regards,
Beno�t

[This message has been edited by Beno�t d'Oncieu (edited October 31, 2000).]
 
reply
    Bookmark Topic Watch Topic
  • New Topic