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.

All functions