> ## Documentation Index
> Fetch the complete documentation index at: https://new.docs.falkordb.com/llms.txt
> Use this file to discover all available pages before exploring further.

# bitwise.and

> Performs a bitwise AND operation on two integers, returning 1 for each bit position where both operands have a 1.

## Description

Performs a bitwise AND operation on two integers. Each bit in the result is 1 only if the corresponding bits in both operands are 1.

## Syntax

```cypher theme={null}
flex.bitwise.and(a, b)
```

## Parameters

| Parameter | Type             | Required | Description    |
| --------- | ---------------- | -------- | -------------- |
| `a`       | number (integer) | Yes      | First operand  |
| `b`       | number (integer) | Yes      | Second operand |

## Returns

**Type:** number (integer)

The result of the bitwise AND operation.

## Examples

### Example 1: Basic AND Operation

```cypher theme={null}
RETURN flex.bitwise.and(12, 10) AS result
```

**Output:**

```text theme={null}
result
------
8
```

(Binary: 1100 AND 1010 = 1000 = 8)

### Example 2: Checking Permission Flags

```cypher theme={null}
WITH 7 AS userPermissions  // 0111 (read=1, write=2, execute=4)
WITH userPermissions, 2 AS writeFlag
RETURN flex.bitwise.and(userPermissions, writeFlag) > 0 AS hasWrite
```

### Example 3: Masking Bits

```cypher theme={null}
MATCH (d:Device)
WITH d, flex.bitwise.and(d.flags, 15) AS lowerNibble
RETURN d.id, lowerNibble
```

## Notes

* Operates on 32-bit signed integers in JavaScript
* Both operands are converted to integers if needed
* Commonly used for flag checking and bit masking

## See Also

* [bitwise.or](/udfs/flex/bitwise/or) - Bitwise OR operation
* [bitwise.xor](/udfs/flex/bitwise/xor) - Bitwise XOR operation
* [bitwise.not](/udfs/flex/bitwise/not) - Bitwise NOT operation

## Frequently Asked Questions

<AccordionGroup>
  <Accordion title="What does flex.bitwise.and return?">
    It returns an integer where each bit is 1 only if the corresponding bits in **both** input operands are 1. For example, `flex.bitwise.and(6, 3)` returns `2`.
  </Accordion>

  <Accordion title="Can I use bitwise.and for permission checking?">
    Yes. A common pattern is `flex.bitwise.and(userPermissions, requiredFlag) = requiredFlag` to test whether a specific permission bit is set.
  </Accordion>
</AccordionGroup>
