• 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

 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following code will print
1: int i = 1;
2: i <<= 31; 1*2^31 = 2^31<br /> 3: i >>= 31; 2^31 /2^31 = 1
4: i >>= 1; 1>>=1 1/2 === 0
5:
6: int j = 1;
7: j <<= 31; 1*2^31<br /> 8: j >>= 31; 2^31/2^31 ==1
9:
10: System.out.println("i = " +i );
11: System.out.println("j = " +j);
A) i = 1
j = 1
B) i = -1
j = 1

C) i = 1
j = -1//answer how come???

D) i = -1
j = -1
 
josephine chen
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
where am i going wrong
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For a problem like this, it's useful to print out intermediate results so that you can see for yourself if you're on the right track:


[This message has been edited by Jim Yingst (edited February 22, 2000).]
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For those who search for "shift" on this forum - make sure you follow Jim's advice - check the result!
Hint:it will be D) i=-1, j=-1 .
 
reply
    Bookmark Topic Watch Topic
  • New Topic