Number.BitwiseXor

Number

Performs a bitwise exclusive OR (XOR) operation on two integer values.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

Number.BitwiseXor(number1 as number, number2 as number) as number

Parameters

NameTypeRequiredDescription
number1numberYesThe first integer operand.
number2numberYesThe second integer operand.

Return Value

numberAn integer where each bit is 1 only if the corresponding bits differ between the two inputs.

Remarks

Number.BitwiseXor performs a bitwise exclusive OR (XOR). A bit in the result is 1 when the corresponding bits in the two operands differ — one is 0 and the other is 1. When both bits are the same (both 0 or both 1), the result bit is 0.

XOR has a key algebraic property: applying XOR twice with the same mask is self-inversea XOR b XOR b = a. This makes it useful for:

- Toggling bits: Number.BitwiseXor(flags, mask) flips the mask bits regardless of their current state (unlike OR which only sets, or AND-NOT which only clears) - Comparing two values bit-by-bit: the result bits show exactly which bits differ - Simple reversible encoding: XOR encoding and decoding with the same key

XOR is the bitwise operation most sensitive to the "difference" between two integers — Number.BitwiseXor(x, x) = 0 (a number XORed with itself is always 0), and Number.BitwiseXor(x, 0) = x (XOR with 0 is identity).

Examples

Example 1: Basic XOR — only differing bit positions are set

Result
Result
16

Example 2: Toggle bit 1 (value 2) in a flags integer

Result
Result
17

Example 3: XOR is self-inverse — encoding and decoding with the same mask

let
    Original = 42,
    Mask = 15,
    Encoded = Number.BitwiseXor(Original, Mask),
    Decoded = Number.BitwiseXor(Encoded, Mask)
in
    #table({"Original", "Encoded", "Decoded"}, {{Original, Encoded, Decoded}})
Applied Steps

The final output — a single-row table showing Original = 42, Encoded = 37, and Decoded = 42.

Original
Encoded
Decoded
1423742

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks