aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Integer bitwise operator doubt? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Integer bitwise operator doubt?" Watch "Integer bitwise operator doubt?" New topic
Author

Integer bitwise operator doubt?

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9622
    
    2

Guys,

I have the below doubt regarding ~ operator.

byte b = 3;
~b;
System.out.println(b); // Why it gives 3 instead of -4??


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
My compiler complains when I try to compile that because ~b isn't a statement.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9622
    
    2

Keith,

When we say ++b, it accepts and why does it complain when we say ~b??
Sandeep Rana
Greenhorn

Joined: Dec 01, 2006
Posts: 6
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


Try it out!!!
Anuragk kushwaha
Ranch Hand

Joined: Aug 02, 2006
Posts: 51
yes, it will give compilation error!!!11 Not a Statement

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Integer bitwise operator doubt?