A possible solution using BitSet:
BitSet A = BitSet.valueOf(new long[] { Integer.valueOf("111100000101", 2) });
BitSet B = BitSet.valueOf(new long[] { Integer.valueOf("111100001010", 2) });
A.xor(B); // A holds bits that are in the set state only for A or only for B
int index = A.length() + 1;
while ((index = A.previousSetBit(index - 1)) > 0) { // starting from the end going backward
if (B.get(index)) {
// if the corresponding bit in B is in the set state then the bit in A is not set
break;
}
}
// index is the zero-based index of the first unset bit in byte array A that is set in byte array B,
return index;