I saw an example code on the Java documentation site about bit that can be checked here .
This class belongs to the example that is quoted in link above:
class BitDemo {
public static void main(String[] args) {
int bitmask = 0x000F;
int val = 0x2222;
// prints "2"
System.out.println(val & bitmask);
}
}
My question is about how it is possible that the printed value equals two? How do I get this operation?
I took a calculator and saw that 2222 in hexadecimal corresponds to 8738 and that F in hex is equal to 15 in decimal.
Based on this, how does the expression val & bitmask
result in 2?