• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

operator n assignment

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the result that will be printed out
public class Test {
public static void main(String[] args)
{
int a = -8;
int b = ~ -33;
a>>>=b;
System.out.println(a);
}
}

an is -8..am wondering how to work out such questionsPlease guide on this
 
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hint:
~ is complement of the number In general
~i = - (i + 1); So, ~10 is equal to -1 * (10 + 1) = -11
Similarly ~-10 = -1 * (-10+1) = 9

Let me know if that works for you.
 
pravin kumar
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thnks for the both reply
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
pravin kumar
Here is a short program to explain what is happing it it helps.




The output of the code is :

-33 = 11111111111111111111111111011111
After Conversion ~-33 = 100000
- 8 = 11111111111111111111111111111000
Remember only the last 5 digits are used for -33 shift whick is 0
Results of a>>>b :=-8 >>> 0 = -8
 
reply
    Bookmark Topic Watch Topic
  • New Topic