bitXor

bitXor(x, y)

Try it yourself:


bitXor(): mark differing bits

bitXor(a, b) performs exclusive OR. A result bit is 1 when the inputs differ at that position. Thus bitXor(12, 10) compares 1100 with 1010 and returns 0110, or 6.

A useful toggle

XOR is reversible: applying the same mask twice restores the original value. That makes bitXor(value, mask) useful for toggling selected flags and for simple change detection. It is not encryption; a fixed XOR mask is easily reversed.

Explore the bits

Use bin() to make the differing positions visible. For a union of enabled flags use bitOr(); for shared flags use bitAnd(); use bitNot() to complement a mask.

Use integer values

Bitwise operators are defined for integers. Round fractional measurements deliberately before using them, and take care with negative operands and externally specified word sizes.

Try Bit Xor in Calcul.io

Start with one of the editable examples above, then replace its arguments with your own values. Keeping the function on a separate calculator line makes the input and result easy to compare. For a longer workflow, assign the result to a variable or reference that line in the next expression.

Check the shown signature before adding optional arguments, and use the related-function links to compare operations with similar purposes.

All functions