7

For the first time in 20 years I used and xor operator.
I wrote in line of code instead of two.

How uses the xor operator?

Comments
  • 2
    When you want to output to be false when same and true when different. What do you mean how does one use XOR?
  • 0
    I'm confused. Can you be more specific?
  • 5
    Are you into men xor women
  • 0
    Only when I want to confuse the fuck out the next dev.
    I output errors messges using a random key xor'ed string. unique per error msg. Let them have fun searching trough the code...
  • 4
    You can use it to toggle specific bits:
    x ^= 0x01;
    This will leave all bits of x as they are, except the least significant one, which will change its state.
  • 0
    I use the XAND operator instead.
  • 0
    I would stay away from bitwise operators unless your doing operations on bitfields.

    You can do clever things, but they aren't very clear for maintenance. Maybe if you put it into a well named function call or macro and it's there for speed purposes only.
Add Comment