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

# BITWISE_AND

> Computes the bitwise AND of two numeric values.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Scalar function</span></div>

**Aliases:** [`bitand`](/query/sql/functions/bitwise/bitand)

Returns NULL when either operand is NULL.

## Syntax

### Numeric values

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
bitwise_and(left, right)
```

* Takes exactly two numeric operands. Noninteger numbers are converted to BIGINT and must fit that type.

## Arguments

### Bitwise and integer

| Name | Type | Required | Description |
| - | - | - | - |
| left | TINYINT, SMALLINT, INTEGER or BIGINT | Yes | The first integer. Equal integer types are preserved. With different signed integer types, both operands convert to the wider type in this order: TINYINT, SMALLINT, INTEGER, BIGINT. |
| right | TINYINT, SMALLINT, INTEGER or BIGINT | Yes | The second integer. Equal integer types are preserved. With different signed integer types, both operands convert to the wider type in this order: TINYINT, SMALLINT, INTEGER, BIGINT. |

### Bitwise and numeric cast

| Name | Type | Required | Description |
| - | - | - | - |
| left | TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE or DECIMAL(p, s) | Yes | Operand cast to BIGINT before AND if it is not already an integer. The converted value must fit in BIGINT. For DECIMAL(p, s), p is precision (total digits) and s is scale (digits after the decimal point). |
| right | TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE or DECIMAL(p, s) | Yes | Operand cast to BIGINT before AND if it is not already an integer. The converted value must fit in BIGINT. For DECIMAL(p, s), p is precision (total digits) and s is scale (digits after the decimal point). |

## Returns

* Type: bitwise and integer: TINYINT, SMALLINT, INTEGER or BIGINT: the wider signed integer input type; bitwise and numeric cast: BIGINT when at least one operand is a noninteger numeric value
* Possible values: Each output bit is 1 only when both corresponding input bits are 1.
* NULL behavior: Returns NULL when either operand is NULL.

### Bitwise and integer

* Type: TINYINT, SMALLINT, INTEGER or BIGINT: the wider signed integer input type
* Possible values: Each output bit is 1 only when both corresponding input bits are 1.
* NULL behavior: Returns NULL when either integer operand is NULL.

### Bitwise and numeric cast

* Type: BIGINT when at least one operand is a noninteger numeric value
* Possible values: The bitwise AND of the converted signed BIGINT operands.
* NULL behavior: NULL numeric inputs remain NULL through conversion and produce NULL.

## Properties

| Property | Value |
| - | - |
| Deterministic | Yes |
| Supports window usage | No |
| Exact result | Yes |

## Usage notes

* Integer operands are converted to a common integer type. BITWISE\_AND also converts noninteger numeric inputs to BIGINT; BITAND does not accept those inputs.
* INTEGER and INT mean the same type; STRING means VARCHAR text. NULL can be used with a supported type. Cast NULL explicitly when its type would otherwise be unclear.

## Examples

### Example values

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT bitwise_and(CAST(6 AS BIGINT), CAST(3 AS BIGINT)) AS "value";
```

| value |
| - |
| 2 |

### Keep the common set bits

In binary, 1100 AND 1010 is 1000, which is 8.

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT bitwise_and(CAST(12 AS BIGINT), CAST(10 AS BIGINT)) AS common_bits;
```

| common\_bits |
| - |
| 8 |

## Limitations

* BITWISE\_AND accepts exactly two numeric operands. BINARY operands and a third padside argument are not supported; use BITAND for binary values.
* BITWISE\_AND converts noninteger numeric operands to BIGINT before the bitwise operation. Values that cannot be converted can raise an error. Query tools may report the first argument’s type even when the result is BIGINT.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.