The result of -bxor is a number where the bits are set in either the value on the left, or the value on the right, but not both.
In the following example, the result is 11:
6 -bxor 13
This operation can be shown in a table:
Bit value |
8 |
4 |
2 |
1 |
|
Left-hand side |
6 |
0 |
1 |
1 |
0 |
Right-hand side |
13 |
1 |
1 |
0 |
1 |
-band |
11 |
1 |
0 |
1 |
1 |
The -bxor operator is useful for toggling bit values. For example, bxor might be used to toggle the AccountDisable bit of UserAccountControl in Active Directory:
512 -bxor 2 # Result is 514 (Disabled, 2 is set) 514 -bxor 2 # Result is 512 (Enabled, 2 is not set)