Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

bitwise operator

 
prafulla shrikhande
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this was a good one on bitwise operators -

i = 1;

i <<= 31;
i >>= 31;
i >>= 1;

whats the value of i?
 
Pedro Ivo Dantas
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on the type of the variable i. If it is a int, as I suppose was your intention, then the resulting value will be -1 (11111...1111). If it is a long, then the result will be 0.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic