This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes  what does bit wise operator '&' does here ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark " what does bit wise operator Watch " what does bit wise operator New topic
Author

what does bit wise operator '&' does here ?

naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 688

what does bit wise operator '&' does here ? addition, substraction, division, modulus or what ?


The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4338
    
    7

It does a bit-wise AND.

So, if no is (in binary) 10111001 (for instance), then i & 1 would be 10111001 & 00000001, which is 00000001, or 1. The last digit is the only one that is 1 in both numbers.

So what that's doing is testing if the last binary digit is 1 or not. In this case, it's equivalent to testing whether the number is even or not, and so you could do the equivalent as (no % 2 == 1).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what does bit wise operator '&' does here ?
 
Similar Threads
SHIFT PROBLEM
confusion about bit-wise operators
Java Sets Project
Most Significant bit
Java leftshift operator add 1 instead of 0