# GETBIT

> Return the value of one bit of the string stored at a key.

URL: https://docs.hotkv.com/commands/getbit/

```
GETBIT key offset
```

- Group: Bitmap
- Complexity: O(1)
- HotKV Cloud: all plans
- On-Premise: no license needed

`GETBIT` returns the bit at `offset` in the string at `key`. Bit 0 is the most
significant bit of the first byte. Bits past the end of the string, and every
bit of a missing key, read as `0`. `offset` must be at least 0 and below the
number of bits in the largest allowed string (2^32 with the default
`proto-max-bulk-len` of 512 MB).

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Always | Integer: `0` or `1` | Integer |

Errors:

- `ERR bit offset is not an integer or out of range` for a bad `offset`.
- `WRONGTYPE` when the key holds a value that is not a string.

## Examples

```
127.0.0.1:6379> SETBIT flags 7 1
(integer) 0
127.0.0.1:6379> GETBIT flags 7
(integer) 1
127.0.0.1:6379> GETBIT flags 100
(integer) 0
127.0.0.1:6379> GETBIT missing 0
(integer) 0
```

## Compatibility

Same as Redis 7 and Valkey 8.

## See also

[SETBIT](https://docs.hotkv.com/commands/setbit/index.md), [BITCOUNT](https://docs.hotkv.com/commands/bitcount/index.md),
[BITFIELD_RO](https://docs.hotkv.com/commands/bitfield_ro/index.md)