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

# GETBIT

> Returns the bit at a zero-based position in an integer.

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

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

Returns NULL when an argument is NULL.

## Syntax

### Scalar

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
getbit(value, position)
```

## Arguments

| Name | Type | Required | Description |
| - | - | - | - |
| value | INTEGER | Yes | The integer to inspect. |
| position | INTEGER | Yes | The bit position, counted from the least significant bit. 0 \<= position \< width of value (8, 16, 32 or 64). |

## Returns

* Type: TINYINT
* Possible values: 0 or 1.
* NULL behavior: Returns NULL when an argument is NULL.

## Properties

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

## Examples

### Position and NULL input

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT getbit(5, 0) AS low_bit, getbit(5, 1) AS next_bit, getbit(CAST(NULL AS INT), 0) AS null_value;
```

| low\_bit | next\_bit | null\_value |
| - | - | - |
| 1 | 0 | NULL |

### Read set and unset positions

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT getbit(CAST(8 AS INT), 3) AS set_bit, getbit(CAST(8 AS INT), 2) AS unset_bit;
```

| set\_bit | unset\_bit |
| - | - |
| 1 | 0 |

## Limitations

* Negative positions and positions at least as large as the integer width raise an execution error.


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