• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Integer bitwise operator doubt?

 
Joe Harry
Ranch Hand
Posts: 10112
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

I have the below doubt regarding ~ operator.

byte b = 3;
~b;
System.out.println(b); // Why it gives 3 instead of -4??
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My compiler complains when I try to compile that because ~b isn't a statement.
 
Joe Harry
Ranch Hand
Posts: 10112
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keith,

When we say ++b, it accepts and why does it complain when we say ~b??
 
Sandeep Rana
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's correct that it will give error "not a statement", moreover logically you are not assigning this ~b value to any variable. Any way this is b is same... You have not change the value of b.

If you will do something like
int c = ~b;
then c is -4

Hope you got the point
 
Anuragk kushwaha
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, it will give compilation error!!!11 Not a Statement

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic