KodeWarrior - 1 year ago 135

C Question

I came across the following code snippet

`if( 0 != ( x ^ 0x1 ) )`

encode( x, m );

What does

`x ^ 0x1`

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

The XOR operation (`x ^ 0x1`

) inverts bit 0. So the expression effectively means: if bit 0 of x is 0, or any other bit of x is 1, then the expression is true.

Conversely the expression is false if x == 1.

So the test is the same as:

```
if (x != 1)
```

and is therefore (arguably) unnecessarily obfuscated.

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**