Théo Driutti
Théo Driutti

Reputation: 37

Is there a bitwise equivalent of boolA == boolB?

I know I can do bool ^= true to reverse its value but is there a similar operator to evaluate boolA == boolB without the == operator? I don't know much about bitwise but I haven't found any answer online yet.

It would be something like

bool a = false;
bool b = true;
bool c = a /*some sign, like ^ or ~ or something */ b;
Debug.Log(c);
// output: false

Upvotes: 1

Views: 94

Answers (1)

CoderCharmander
CoderCharmander

Reputation: 1910

You should be able to use the XOR operator (^). XOR returns 1 if the input bits are different, so it can be counted as a bitwise !=. After that, you can invert the bits with the ~ (NOT) unary operator. You can do it like this:

~(0b1010 ^ 0b1100) // 0b1001

Upvotes: 4

Related Questions