---
name: "bitarr"
section: "3pub"
platform: "linux"
package: "publib-dev"
version: "0.40-4"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/bitarr"
---

# bitarr(3pub)

bit array manipulation

## NAME

ba\_and\_ba, ba\_clear, ba\_clear\_all, ba\_copy, ba\_create, ba\_destroy, ba\_not, ba\_or\_ba, ba\_or\_not\_ba, ba\_query, ba\_resize, ba\_set, ba\_xor\_ba - bit array manipulation

## SYNOPSIS

```
#include <bitarr.h>

Bitarr *ba_create(void);
void ba_destroy(Bitarr *ba);
Bitarr *ba_copy(const Bitarr *ba);
int ba_resize(Bitarr *ba, size_t max_number);

int ba_set(Bitarr *ba, unsigned number);
int ba_clear(Bitarr *ba, unsigned number);
void ba_clear_all(Bitarr *ba);
int ba_query(Bitarr *ba, unsigned number);
void ba_and_ba(Bitarr *ba1, const Bitarr *ba2);
int ba_or_ba(Bitarr *ba1, const Bitarr *ba2);
void ba_xor_ba(Bitarr *ba1, const Bitarr *ba2);
void ba_or_not_ba(Bitarr *ba1, const Bitarr *ba2);
void ba_not(Bitarr *ba);
```

## DESCRIPTION

These functions operate on bit arrays. *ba\_create* creates one and *ba\_destroy* it. *ba\_copy* makes a copy of one, and *ba\_resize* changes its size. The bit arrays resize themselves automatically, but *ba\_resize* can be used to get rid of extra memory allocated for the array, or to make sure there is enough memory allocated for the array (so that further operations are guaranteed to work).

*ba\_set* sets one element (bit) in the array to 1. *ba\_clear* clears one element (sets it to 0), *ba\_clear\_all* clears all elements. *ba\_query* returns the current value of an element.

*ba\_and\_ba*, *ba\_or\_ba*, *ba\_xor\_ba*, and *ba\_or\_ba* do logical operations on two arrays. The result will be stored in the first one. *ba\_not* will invert all elements in the array.

## RETURNS

*ba\_create* and *ba\_copy* return a pointer to the new array, or NULL if they fail. Those that return an integer, return -1 for error, non-negative for success.

## SEE ALSO

publib(3), iset(3)

## AUTHOR

Lars Wirzenius (lars.wirzenius@helsinki.fi)
