---
name: "libbitmask"
section: "3"
platform: "linux"
package: "libbitmask1"
version: "2.0-5+b2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/libbitmask"
---

# libbitmask(3)

Dynamically sized multi-word bit masks.

## NAME

bitmask, bitmask\_alloc, bitmask\_free, bitmask\_displayhex, bitmask\_displaylist, bitmask\_parsehex, bitmask\_parselist, bitmask\_copy, bitmask\_setall, bitmask\_clearall, bitmask\_nbytes, bitmask\_mask, bitmask\_nbits, bitmask\_weight, bitmask\_isbitset, bitmask\_isbitclear, bitmask\_isallset, bitmask\_isallclear, bitmask\_setbit, bitmask\_clearbit, bitmask\_equal, bitmask\_subset, bitmask\_disjoint, bitmask\_intersects, bitmask\_setrange, bitmask\_clearrange, bitmask\_keeprange, bitmask\_complement, bitmask\_shiftright, bitmask\_shiftleft, bitmask\_and, bitmask\_andnot, bitmask\_or, bitmask\_eor, bitmask\_first, bitmask\_next, bitmask\_rel\_to\_abs\_pos, bitmask\_abs\_to\_rel\_pos, bitmask\_last\
  \- Dynamically sized multi-word bit masks.

## SYNOPSIS

```
#include <bitmask.h>

cc ... -lbitmask

```

### Allocate and free \`struct bitmask \*\`:

```
struct bitmask *bitmask_alloc(unsigned int nbits);
void bitmask_free(struct bitmask *bmp);
```

### Display and parse ascii string representations:

```
int bitmask_displayhex(char *buf, int len, const struct bitmask *bmp);
int bitmask_displaylist(char *buf, int len, const struct bitmask *bmp);
int bitmask_parsehex(const char *buf, struct bitmask *bmp);
int bitmask_parselist(const char *buf, struct bitmask *bmp);
```

### Basic initialization operations:

```
struct bitmask *bitmask_copy(struct bitmask *bmp1, const bitmask *bmp2);
struct bitmask *bitmask_setall(struct bitmask *bmp);
struct bitmask *bitmask_clearall(struct bitmask *bmp);
```

### Interface to kernel sched\_{set,get}affinity system calls:

```
unsigned int bitmask_nbytes(struct bitmask *bmp);
unsigned long *bitmask_mask(struct bitmask *bmp);
```

### Unary numeric queries:

```
unsigned int bitmask_nbits(const struct bitmask *bmp);
unsigned int bitmask_weight(const struct bitmask *bmp);
```

### Unary Boolean queries:

```
int bitmask_isbitset(const struct bitmask *bmp, unsigned int i);
int bitmask_isbitclear(const struct bitmask *bmp, unsigned int i);
int bitmask_isallset(const struct bitmask *bmp);
int bitmask_isallclear(const struct bitmask *bmp);
```

### Single bit operations:

```
struct bitmask *bitmask_setbit(struct bitmask *bmp, unsigned int i);
struct bitmask *bitmask_clearbit(struct bitmask *bmp, unsigned int i);
```

### Binary Boolean operations: bmp1 op? bmp2:

```
int bitmask_equal(const struct bitmask *bmp1, const bitmask *bmp2);
int bitmask_subset(const struct bitmask *bmp1, const bitmask *bmp2);
int bitmask_disjoint(const struct bitmask *bmp1, const bitmask *bmp2);
int bitmask_intersects(const struct bitmask *bmp1, const bitmask *bmp2);
```

### Range operations:

```
struct bitmask *bitmask_setrange(struct bitmask *bmp, unsigned int i, unsigned int j);
struct bitmask *bitmask_clearrange(struct bitmask *bmp, unsigned int i, unsigned int j);
struct bitmask *bitmask_keeprange(struct bitmask *bmp, unsigned int i, unsigned int j);
```

### Unary operations:

```
struct bitmask *bitmask_complement(struct bitmask *bmp1, const bitmask *bmp2);
struct bitmask *bitmask_shiftright(struct bitmask *bmp1, const bitmask *bmp2, unsigned int n);
struct bitmask *bitmask_shiftleft(struct bitmask *bmp1, const bitmask *bmp2, unsigned int n);
```

### Binary operations:

```
struct bitmask *bitmask_and(struct bitmask *bmp1, const bitmask *bmp2, const bitmask *bmp3);
struct bitmask *bitmask_andnot(struct bitmask *bmp1, const bitmask *bmp2, const bitmask *bmp3);
struct bitmask *bitmask_or(struct bitmask *bmp1, const bitmask *bmp2, const bitmask *bmp3);
struct bitmask *bitmask_eor(struct bitmask *bmp1, const bitmask *bmp2, const bitmask *bmp3);
```

### Iteration operators:

```
int bitmask_first(const struct bitmask *bmp);
unsigned int bitmask_next(const struct bitmask *bmp, unsigned int i);
unsigned int bitmask_rel_to_abs_pos(const struct bitmask *bmp, unsigned int n);
unsigned int bitmask_abs_to_rel_pos(const struct bitmask *bmp, unsigned int n);
unsigned int bitmask_last(const struct bitmask *bmp);
```

## DESCRIPTION

See further /usr/share/doc/packages/libbitmask/libbitmask.html. This document is also available in plain text format as /usr/share/doc/packages/libbitmask/libbitmask.txt.

## SEE ALSO

[**cpuset**(1)](/cpuset/1.md), [**libcpuset**(3)](/libcpuset/3.md), **bootcpuset.conf**(5), **bootcpuset**(8).

## AUTHOR

pj@sgi.com (Paul Jackson)
