Number.BitwiseAnd
NumberPerforms a bitwise AND operation on two integer values.
Syntax
Number.BitwiseAnd(number1 as number, number2 as number) as numberParameters
| Name | Type | Required | Description |
|---|---|---|---|
number1 | number | Yes | The first integer operand. |
number2 | number | Yes | The second integer operand. |
Return Value
number — An integer where each bit is 1 only if the corresponding bit is 1 in both inputs.
Remarks
Number.BitwiseAnd performs a bitwise AND between two integers. Each bit position in the result is 1 only when the corresponding bit is 1 in both operands; otherwise it is 0. Both inputs are treated as integers — any fractional part is truncated before the operation.
The most common use of bitwise AND is bit masking: extracting or testing specific bits within a packed integer value. Practical scenarios in Power Query include:
- Flag testing: checking whether a specific capability or status bit is set in an integer flags column (e.g., Number.BitwiseAnd(flags, 4) > 0 tests bit 2)
- Permission bitmasks: determining whether a user's permission integer includes a specific right
- Extracting byte fields: isolating the lower N bits of a packed value using a mask like 15 (0xF, lower 4 bits) or 255 (0xFF, lower 8 bits)
Note that bitwise operations in Power Query M are 64-bit integer operations. Values are cast to 64-bit signed integers before the operation, which can produce unexpected results if you pass large floating-point numbers.
Examples
Example 2: Test whether bit 2 (value 4) is set in a flags integer
Number.BitwiseAnd(7, 4) > 0Result | |
|---|---|
| 1 | TRUE |
Example 3: Extract the lower 4 bits (nibble) using mask 15 (0xF)
Number.BitwiseAnd(181, 15)Result | |
|---|---|
| 1 | 5 |