BITMASK

BITMASK(value)[source]

Converts an array of booleans into a single integer bitmask.

A bitmask is an integer that compactly encodes an array of boolean values. Each element in the array is mapped to a bit (True as 1, False as 0) with the first element representing the least significant bit. For example, [True, False, True, True] becomes binary 1101, which equals the integer value 13. This representation is efficient for storage, comparison, and bitwise operations.

Parameters:

value (Operand) –

A model component representing a boolean array to convert into a bitmask.

Supported types:

  • BOOLEAN_ARRAY

Return type:

Formula

Returns:

An integer whose binary representation encodes the boolean array.

Supported types:

  • INTEGER

Raises:

ValueError – If the input is not of type BOOLEAN_ARRAY.

Examples

Basic usage:

BITMASK([True, False, True, True])
# Returns 13 (binary 1101)

Using a field:

BITMASK(order["flags"])
# Converts the boolean flags array into an integer bitmask

Note

The platform supports up to 32 bits in a bitmask. Therefore, if the input boolean array has a size greater than 32, information will be lost. For such cases, consider using BITMASKSTRING instead, which returns a hexadecimal string representation of the bitmask.