Number.BitwiseNot

Number

Performs a bitwise NOT (bitwise complement) on an integer value, flipping all bits.

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

Syntax

Number.BitwiseNot(number as number) as number

Parameters

NameTypeRequiredDescription
numbernumberYesThe integer whose bits are flipped.

Return Value

numberThe 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 1: Bitwise NOT of 0 returns -1

Result
Result
1-1

Example 2: Bitwise NOT of 5 returns -6

Result
Result
1-6

Example 3: Clear a specific bit from a flags value using NOT as an inverse mask

Result
Result
13

Compatibility

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