.\" Copyright (c) 1989, 1991 The Regents of the University of California.
.\" This code is derived from software contributed to Berkeley by
.\" %sccs.include.redist.man%
.\" @(#)bitstring.3 5.4 (Berkeley) %G%
.Nd bit-string manipulation macros
.Fd #include <bitstring.h>
.Fn bit_alloc "int nbits"
.Fn bit_decl "bit_str name" "int nbits"
.Fn bit_clear "bit_str name" "int bit"
.Fn bit_ffc "bit_str name" "int nbits" "int *value"
.Fn bit_ffs "bit_str name" "int nbits" "int *value"
.Fn bit_nclear "bit_str name" "int start" "int stop"
.Fn bit_nset "bit_str name" "int start" "int stop"
.Fn bit_set "bit_str name" "int bit"
.Fn bitstr_size "int nbits"
.Fn bit_test "bit_str name" "int bit"
These macros operate on strings of bits.
returns a pointer of type
to sufficient space to store
if no space is available.
allocates sufficient space to store
returns the number of elements of type
This is useful for copying bit strings.
clear or set the zero-based numbered bit
set or clear the zero-based numbered bits from
evaluates to zero if the zero-based numbered bit
is set, and non-zero otherwise.
stores in the location referenced by
the zero-based number of the first bit set in the array of
If no bits are set, the location referenced by
stores in the location referenced by
the zero-based number of the first bit not set in the array of
If all bits are set, the location referenced by
The arguments to these macros are evaluated only once and may safely
.Bd -literal -offset indent
#define LPR_DOWNLOAD_BIT 2
#define LPR_AVAILABLE_BIT 9
bitstr_t bit_decl(bitlist, LPR_MAX_BITS);
bit_nclear(bitlist, 0, LPR_MAX_BITS - 1);
if (!bit_test(bitlist, LPR_BUSY_BIT)) {
bit_clear(bitlist, LPR_FORMAT_BIT);
bit_clear(bitlist, LPR_DOWNLOAD_BIT);
bit_set(bitlist, LPR_AVAILABLE_BIT);