> ## 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.

# BITAND

> Computes the bitwise AND of two integers or two binary values.

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

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

Returns NULL when either operand is NULL. A NULL padside argument is rejected.

## Syntax

### Integers or binary values

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

* For BINARY inputs, both byte sequences must have the same length.

### Binary values with padding

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

* Zero-pad the shorter byte sequence to match the longer one.

### Alias: BITWISE\_AND (numeric values only)

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

* Takes exactly two numeric operands. Integer operands use a common integer type. Other numeric operands are converted to BIGINT and must fit that type.
* BITWISE\_AND does not accept BINARY inputs or a padside argument.

## Arguments

### Integer, 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. |

### Binary

| Name | Type | Required | Description |
| - | - | - | - |
| left | BINARY | Yes | The first byte sequence. |
| right | BINARY | Yes | The second byte sequence. |

### Binary padding

| Name | Type | Required | Description |
| - | - | - | - |
| left | BINARY | Yes | The first byte sequence. |
| right | BINARY | Yes | The second byte sequence. |
| padside | STRING | Yes | The side on which zero padding is added. 'LEFT' or 'RIGHT' (case-insensitive). Must be a constant argument. |

### 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: TINYINT, SMALLINT, INTEGER or BIGINT for integer operands (the wider input type); BINARY for binary operands
* Possible values: Each output bit is 1 only when both corresponding input bits are 1.
* NULL behavior: Returns NULL when either operand is NULL. A NULL padside argument is rejected.

### Binary, Binary padding

* Type: BINARY
* Possible values: Each output bit is 1 only when both corresponding input bits are 1.
* NULL behavior: Returns NULL when either binary 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

* Binary operands of unequal lengths require a padside argument. Zero bytes are added on the requested side of the shorter operand.
* 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

### Integer AND

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

| value |
| - |
| 2 |

### 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 |

## Limitations

* Without padside, unequal binary lengths raise an execution error.
* padside must be a string literal LEFT or RIGHT (case-insensitive); NULL, arbitrary expressions and other strings are rejected.
* 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.