# Chalk SQL Reference: Bitwise Functions
source: https://docs.chalk.ai/chalksql-docs#section-bitwise-functions

## `bit_count(x, bits)`
source: https://docs.chalk.ai/chalksql-docs#bit_count

Counts the number of `bits` in ``x``.

**Parameters**

- `x`: `int64`
  The input value.
- `bits`: `int64`
  The bit width to operate within.

## `bitwise_and(x, y)`
source: https://docs.chalk.ai/chalksql-docs#bitwise_and

Performs bitwise AND operation on two integer values.

**Overloads**

#### `bitwise_and(x, y)`

**Parameters**

- `x`: `int8`
  The input value.
- `y`: `int8`
  The second input value.

#### `bitwise_and(x, y)`

**Parameters**

- `x`: `int16`
  The input value.
- `y`: `int16`
  The second input value.

#### `bitwise_and(x, y)`

**Parameters**

- `x`: `int32`
  The input value.
- `y`: `int32`
  The second input value.

#### `bitwise_and(x, y)`

**Parameters**

- `x`: `int64`
  The input value.
- `y`: `int64`
  The second input value.

## `bitwise_arithmetic_shift_right(x, shift)`
source: https://docs.chalk.ai/chalksql-docs#bitwise_arithmetic_shift_right

Returns the arithmetic right `shift` operation on `x` in 2’s complement representation. `shift` must not be negative.

**Parameters**

- `x`: `int64`
  The input value.
- `shift`: `int64`

## `bitwise_left_shift(x, shift)`
source: https://docs.chalk.ai/chalksql-docs#bitwise_left_shift

Returns the left shifted value of `x`.

**Overloads**

#### `bitwise_left_shift(x, shift)`

**Parameters**

- `x`: `int8`
  The input value.
- `shift`: `int32`

#### `bitwise_left_shift(x, shift)`

**Parameters**

- `x`: `int16`
  The input value.
- `shift`: `int32`

#### `bitwise_left_shift(x, shift)`

**Parameters**

- `x`: `int32`
  The input value.
- `shift`: `int32`

#### `bitwise_left_shift(x, shift)`

**Parameters**

- `x`: `int64`
  The input value.
- `shift`: `int32`

## `bitwise_logical_shift_right(x, shift, bits)`
source: https://docs.chalk.ai/chalksql-docs#bitwise_logical_shift_right

Returns the logical right `shift` operation on `x` (treated as `bits`-bit integer) shifted by `shift`. `shift` must not be negative.

**Parameters**

- `x`: `int64`
  The input value.
- `shift`: `int64`
- `bits`: `int64`
  The bit width to operate within.

## `bitwise_not(x)`
source: https://docs.chalk.ai/chalksql-docs#bitwise_not

Performs bitwise NOT operation (complement) on an integer value.

**Overloads**

#### `bitwise_not(x)`

**Parameters**

- `x`: `int8`
  The input value.

#### `bitwise_not(x)`

**Parameters**

- `x`: `int16`
  The input value.

#### `bitwise_not(x)`

**Parameters**

- `x`: `int32`
  The input value.

#### `bitwise_not(x)`

**Parameters**

- `x`: `int64`
  The input value.

## `bitwise_or(x, y)`
source: https://docs.chalk.ai/chalksql-docs#bitwise_or

Performs bitwise OR operation on two integer values.

**Overloads**

#### `bitwise_or(x, y)`

**Parameters**

- `x`: `int8`
  The input value.
- `y`: `int8`
  The second input value.

#### `bitwise_or(x, y)`

**Parameters**

- `x`: `int16`
  The input value.
- `y`: `int16`
  The second input value.

#### `bitwise_or(x, y)`

**Parameters**

- `x`: `int32`
  The input value.
- `y`: `int32`
  The second input value.

#### `bitwise_or(x, y)`

**Parameters**

- `x`: `int64`
  The input value.
- `y`: `int64`
  The second input value.

## `bitwise_right_shift(x, shift)`
source: https://docs.chalk.ai/chalksql-docs#bitwise_right_shift

Returns the logical right shifted value of `x`.

**Overloads**

#### `bitwise_right_shift(x, shift)`

**Parameters**

- `x`: `int8`
  The input value.
- `shift`: `int32`

#### `bitwise_right_shift(x, shift)`

**Parameters**

- `x`: `int16`
  The input value.
- `shift`: `int32`

#### `bitwise_right_shift(x, shift)`

**Parameters**

- `x`: `int32`
  The input value.
- `shift`: `int32`

#### `bitwise_right_shift(x, shift)`

**Parameters**

- `x`: `int64`
  The input value.
- `shift`: `int32`

## `bitwise_right_shift_arithmetic(x, shift)`
source: https://docs.chalk.ai/chalksql-docs#bitwise_right_shift_arithmetic

Returns the arithmetic right `shift` value of `x`.

**Overloads**

#### `bitwise_right_shift_arithmetic(x, shift)`

**Parameters**

- `x`: `int8`
  The input value.
- `shift`: `int32`

#### `bitwise_right_shift_arithmetic(x, shift)`

**Parameters**

- `x`: `int16`
  The input value.
- `shift`: `int32`

#### `bitwise_right_shift_arithmetic(x, shift)`

**Parameters**

- `x`: `int32`
  The input value.
- `shift`: `int32`

#### `bitwise_right_shift_arithmetic(x, shift)`

**Parameters**

- `x`: `int64`
  The input value.
- `shift`: `int32`

## `bitwise_shift_left(x, shift, bits)`
source: https://docs.chalk.ai/chalksql-docs#bitwise_shift_left

Returns the left `shift` operation on `x` (treated as `bits`-bit integer) shifted by `shift`. `shift` must not be negative.

**Parameters**

- `x`: `int64`
  The input value.
- `shift`: `int64`
- `bits`: `int64`
  The bit width to operate within.

## `bitwise_xor(x, y)`
source: https://docs.chalk.ai/chalksql-docs#bitwise_xor

Performs bitwise XOR operation on two integer values.

**Overloads**

#### `bitwise_xor(x, y)`

**Parameters**

- `x`: `int8`
  The input value.
- `y`: `int8`
  The second input value.

#### `bitwise_xor(x, y)`

**Parameters**

- `x`: `int16`
  The input value.
- `y`: `int16`
  The second input value.

#### `bitwise_xor(x, y)`

**Parameters**

- `x`: `int32`
  The input value.
- `y`: `int32`
  The second input value.

#### `bitwise_xor(x, y)`

**Parameters**

- `x`: `int64`
  The input value.
- `y`: `int64`
  The second input value.

## `x & y`
source: https://docs.chalk.ai/chalksql-docs#%26

Applies boolean AND or bitwise AND to two values.

**Examples**

```sql
SELECT TRUE & FALSE;
```

```text
false
```

```sql
SELECT 6 & 3;
```

```text
2
```

**Overloads**

#### `x & y`

boolean & operation

**Parameters**

- `x`: `bool`
  The input value.
- `y`: `bool`
  The second input value.

#### `x & y`

boolean & operation

**Parameters**

- `x`: `bool`
  The input value.
- `y`: `bool`
  The second input value.

#### `x & y`

Performs bitwise AND operation on two integer values.

**Parameters**

- `x`: `int8`
  The input value.
- `y`: `int8`
  The second input value.

#### `x & y`

Performs bitwise AND operation on two integer values.

**Parameters**

- `x`: `int16`
  The input value.
- `y`: `int16`
  The second input value.

#### `x & y`

Performs bitwise AND operation on two integer values.

**Parameters**

- `x`: `int32`
  The input value.
- `y`: `int32`
  The second input value.

#### `x & y`

Performs bitwise AND operation on two integer values.

**Parameters**

- `x`: `int64`
  The input value.
- `y`: `int64`
  The second input value.

## `arg1 << arg2`
source: https://docs.chalk.ai/chalksql-docs#%3C%3C

Alias for [bitwise_shift_left](https://docs.chalk.ai/chalksql-docs#bitwise_shift_left).

## `x | y`
source: https://docs.chalk.ai/chalksql-docs#%7C

Applies boolean OR or bitwise OR to two values.

**Examples**

```sql
SELECT TRUE | FALSE;
```

```text
true
```

```sql
SELECT 4 | 1;
```

```text
5
```

**Overloads**

#### `x | y`

boolean | operation

**Parameters**

- `x`: `bool`
  The input value.
- `y`: `bool`
  The second input value.

#### `x | y`

boolean | operation

**Parameters**

- `x`: `bool`
  The input value.
- `y`: `bool`
  The second input value.

#### `x | y`

Performs bitwise OR operation on two integer values.

**Parameters**

- `x`: `int8`
  The input value.
- `y`: `int8`
  The second input value.

#### `x | y`

Performs bitwise OR operation on two integer values.

**Parameters**

- `x`: `int16`
  The input value.
- `y`: `int16`
  The second input value.

#### `x | y`

Performs bitwise OR operation on two integer values.

**Parameters**

- `x`: `int32`
  The input value.
- `y`: `int32`
  The second input value.

#### `x | y`

Performs bitwise OR operation on two integer values.

**Parameters**

- `x`: `int64`
  The input value.
- `y`: `int64`
  The second input value.

## `~x`
source: https://docs.chalk.ai/chalksql-docs#~

Applies boolean NOT or bitwise NOT to a value.

**Examples**

```sql
SELECT ~TRUE;
```

```text
false
```

**Overloads**

#### `~x`

boolean ~ operation

**Parameters**

- `x`: `bool`
  The input value.

#### `~x`

boolean ~ operation

**Parameters**

- `x`: `bool`
  The input value.

#### `~x`

Performs bitwise NOT operation (complement) on an integer value.

**Parameters**

- `x`: `int8`
  The input value.

#### `~x`

Performs bitwise NOT operation (complement) on an integer value.

**Parameters**

- `x`: `int16`
  The input value.

#### `~x`

Performs bitwise NOT operation (complement) on an integer value.

**Parameters**

- `x`: `int32`
  The input value.

#### `~x`

Performs bitwise NOT operation (complement) on an integer value.

**Parameters**

- `x`: `int64`
  The input value.
