# bitAnd() Function & Examples

Use the bitAnd() bitwise function in Calcul.io. Review its syntax, edit working examples, understand the result, and explore related math functions.

## bitAnd

#### x & y

#### bitAnd(x, y)

Try it yourself:

```calculio
5 & 3
bitAnd(53, 131)
[1, 12, 31] & 42
```

---

## bitAnd(): combine matching bits

**bitAnd(a, b)** performs a bitwise AND. A result bit is 1 only when the corresponding bit is 1 in both inputs. For example, `bitAnd(12, 10)` compares `1100` and `1010`, producing `1000`, or 8.

## Masks and permissions

AND is the standard way to test a bit mask. If a flag is present in a value, `bitAnd(value, flag)` returns a non-zero result. This is compact and fast for sets of Boolean options such as feature switches or file permissions.

## Inspect the calculation

Use [bin()](https://calcul.io/function/bin/index.md) to see both operands in binary. To set flags, use [bitOr()](https://calcul.io/function/bitOr/index.md); to toggle differences, use [bitXor()](https://calcul.io/function/bitXor/index.md). [bitNot()](https://calcul.io/function/bitNot/index.md) can clear selected positions when combined carefully.

## Input rules

Bitwise operations are intended for integers. Decide explicitly how to handle decimal inputs, and be cautious with negative numbers because signed binary representations and width conventions affect their interpretation. For logical truth values rather than integer bits, use [and](https://calcul.io/function/and/index.md).

[All functions](https://calcul.io/functions/index.md)
