I’m trying to perform a bitwise operation on a BitArray that would result in:
1010
0011
= 1000
So whenever the first bit is set and the corresponding bit is not set (1-0) it returns 1. all other scenarios (0-0,1-1,0-1) result in 0.
How can I achieve this, with or without a bitwise operation?
Performance is critical.
This should work:
Assume ba1 is your first BitArray, and ba2 is your second.
ba1.And(ba2.Not())
should leave ba1 in the state you are looking for in O(2N) time. (but both of your BitArrays will have been modified – more work – and time – required if you need to preserve the source BitArrays by making copies of them).