BITSTRING(3) 386BSD Programmer's Manual BITSTRING(3)
NAME
bitalloc, bitclear, bitdecl, bitffs, bitnclear, bitnset, bitset,
bitstrsize, bittest - bit-string manipulation macros
SYNOPSIS
#include <bitstring.h>
bitstr_t *
bitalloc(int nbits)
bitdecl(bit_str name, int nbits)
bitclear(bit_str name, int bit)
bitffc(bit_str name, int nbits, int *value)
bitffs(bit_str name, int nbits, int *value)
bitnclear(bit_str name, int start, int stop)
bitnset(bit_str name, int start, int stop)
bitset(bit_str name, int bit)
bitstrsize(int nbits)
bittest(bit_str name, int bit)
DESCRIPTION
These macros operate on strings of bits.
The macro bitalloc() returns a pointer of type ``bitstr_t *'' to suffi-
cient space to store nbits bits, or NULL if no space is available.
The macro bitdecl() allocates sufficient space to store nbits bits on
the stack.
The macro bitstrsize() returns the number of elements of type bitstr_t
necessary to store nbits bits. This is useful for copying bit strings.
The macros bitclear() and bitset() clear or set the zero-based numbered
bit bit, in the bit string name.
The bitnset() and bitnclear() macros set or clear the zero-based num-
bered bits from start to stop in the bit string name.
The bittest() macro evaluates to zero if the zero-based numbered bit bit
of bit string name is set, and non-zero otherwise.
The bitffs() macro stores in the location referenced by value the zero-
based number of the first bit set in the array of nbits bits referenced
by name. If no bits are set, the location referenced by value is set to
-1.
The macro bitffc() stores in the location referenced by value the zero-
based number of the first bit not set in the array of nbits bits refer-
enced by name. If all bits are set, the location referenced by value is
set to -1.
The arguments to these macros are evaluated only once and may safely have
side effects.
EXAMPLE
#include <limits.h>
#include <bitstring.h>
#define LPR_BUSY_BIT 0
#define LPR_FORMAT_BIT 1
#define LPR_DOWNLOAD_BIT 2
#define LPR_AVAILABLE_BIT 9
#define LPR_MAX_BITS 10
make_lpr_available()
{
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);
}
}
SEE ALSO
malloc(3)
HISTORY
The bitalloc functions are currently under development.
4th Berkeley Distribution April 19, 1991 3