Number.BitwiseNot
NumberPerforms a bitwise NOT (bitwise complement) on an integer value, flipping all bits.
Syntax
Number.BitwiseNot(number as number) as numberParameters
| Name | Type | Required | Description |
|---|---|---|---|
number | number | Yes | The integer whose bits are flipped. |
Return Value
number — The bitwise complement of the integer, equivalent to -(number + 1).
Remarks
Number.BitwiseNot flips every bit in the integer representation of the input — turning every 0 bit to 1 and every 1 bit to 0. This is the bitwise complement operation. For a 64-bit signed integer representation, the mathematical result is always -(number + 1).
Key reference values: Number.BitwiseNot(0) = -1, Number.BitwiseNot(-1) = 0, Number.BitwiseNot(5) = -6.
The primary use of Number.BitwiseNot is creating the inverse of a bitmask. If you want to clear specific bits from a flags integer, AND the value with NOT of your mask. For example, to clear bit 2 (the flag with value 4) from a flags byte: Number.BitwiseAnd(flags, Number.BitwiseNot(4)). This is the standard "clear bit" idiom used in systems programming.
Note that the result is always a negative number for non-negative inputs, because in two's complement representation, flipping all bits of a non-negative integer always produces a negative value. This can be surprising if you expect an unsigned byte result — in Power Query all integers are signed 64-bit.
Examples
Example 3: Clear a specific bit from a flags value using NOT as an inverse mask
Result | |
|---|---|
| 1 | 3 |