I’m trying to make some bit operations in Java for applying masks, represent sets etc.
Why:
int one=1;
int two=2;
int andop=1&2;
System.out.println(andop);
Prints a “0” when is supposed to be “3”:
0...001
0...010
_______
0...011
And how can I get that behavior?
Thanks in advance
Use the binary ‘or’ operator:
The binary ‘and’ operator will leave bits sets that are in both sides; in the case of
1and2that is no bits at all.