My question might be so basic but I'm still asking this. I reffered this post and what I understood in the logical &
does bitwise AND
0101 & 0011 = 0001
Is there any usecases where we can apply &
on decimal numbers?
For example , if you consider logical ^
(XOR) , it is useful to find unique number in an array, where all the other elements present twice.
Eg: if you have an array [1,1,2,2,3,3,4,4,6,6,7]
and you need to get 7
int[] x = new int[]{1,1,2,2,3,3,4,4,6,6,7};
int y = x[0];
for (int i = 1; i < x.length; i++) {
y ^= x[i];
}
System.out.println(y);
This code will give the result quickly,
Similarly is there any usage of &
in such usecases?