OiO.lk Blog C# Can bitwise operations do this?
C#

Can bitwise operations do this?


I have a basic logic that I can implement with logical operators:

if a == true && b == false

I am wondering if I can do the same with bitwise operators?

XOR does this:

0 ^ 0 = false
0 ^ 1 = true
1 ^ 0 = true
1 ^ 1 = false

If I use XOR, this is what I’m looking for and it will work:

1 ^ 0 = true

However, XOR will also return this, which is NOT what I want:

0 ^ 1 = true

So, is there a way to do it with bitwise operators, without using any logical operators? I have a good understanding of bitwise operations and I can’t see a solution for this, but that doesn’t mean that I couldn’t be missing something.



You need to sign in to view this answers

Exit mobile version