---
title: "bitstring function in Strata | Oplema"
description: "Pad a bitstring with leading zeros until it reaches the length you specify. For example, bitstring('1010'::BITSTRING, 7) returns 0001010."
url: "https://oplema.com/docs/strata/functions/bitstring"
updated: "2026-11-04"
---

# bitstring

Pads the bitstring until the specified length.

## Try an expression

In [Formula](https://oplema.com/docs/strata/prep/formula), enter the expression and set Output type to **VARCHAR**.

### Expression

```
bitstring('1010'::BITSTRING, 7)
```

### Result

```
'0001010'
```

The expression returns `BIT`. Formula stores it as `VARCHAR` in this example. To use your own data, replace the example values with column names. Keep format strings and other options as written.

Try it live in Formula

Result
| id | result |
| --- | --- |
| 1 | 0001010 |

## Arguments and types

```
bitstring(bitstring, length)
```

**bitstring**

Bits, Text

**length**

Number

Supported signatures (2)

```
bitstring(bitstring: BIT, length: INTEGER) → BIT
bitstring(bitstring: VARCHAR, length: INTEGER) → BIT
```

The result type can depend on the input types. See DuckDB for the full argument rules.

## Things to know

If the first argument is missing, the result is NULL.

## Related functions

[bit\_position

Returns first starting index of the specified substring within bits, or zero if it isn't present. The first (leftmost) bit is indexed 1.

](https://oplema.com/docs/strata/functions/bit-position)[get\_bit

Extracts the nth bit from bitstring; the first (leftmost) bit is indexed 0.

](https://oplema.com/docs/strata/functions/get-bit)[set\_bit

Sets the nth bit in bitstring to newvalue; the first (leftmost) bit is indexed 0. Returns a new bitstring.

](https://oplema.com/docs/strata/functions/set-bit)

[Browse bits](https://oplema.com/docs/strata/functions#bits) [DuckDB documentation](https://duckdb.org/docs/current/sql/functions/bitstring.html#bitstringbitstring-length)

Function metadata from DuckDB, used under the [MIT license](https://github.com/duckdb/duckdb/blob/v1.5.4/LICENSE).
