1BITSTRING(3bsd)                      LOCAL                     BITSTRING(3bsd)
2

NAME

4     bit_alloc, bit_clear, bit_decl, bit_ffs, bit_nclear, bit_nset, bit_set,
5     bitstr_size, bit_test — bit-string manipulation macros
6

SYNOPSIS

8     #include <bitstring.h>
9     (See libbsd(7) for include usage.)
10
11     bitstr_t *
12     bit_alloc(int nbits);
13
14     void
15     bit_decl(bitstr_t *name, int nbits);
16
17     void
18     bit_clear(bitstr_t *name, int bit);
19
20     void
21     bit_ffc(bitstr_t *name, int nbits, int *value);
22
23     void
24     bit_ffs(bitstr_t *name, int nbits, int *value);
25
26     void
27     bit_nclear(bitstr_t *name, int start, int stop);
28
29     void
30     bit_nset(bitstr_t *name, int start, int stop);
31
32     void
33     bit_set(bitstr_t *name, int bit);
34
35     int
36     bitstr_size(int nbits);
37
38     int
39     bit_test(bitstr_t *name, int bit);
40

DESCRIPTION

42     These macros operate on strings of bits.
43
44     The macro bit_alloc() returns a pointer of type “bitstr_t *” to suffi‐
45     cient space to store nbits bits, or NULL if no space is available.
46
47     The macro bit_decl() allocates sufficient space to store nbits bits on
48     the stack.
49
50     The macro bitstr_size() returns the number of elements of type bitstr_t
51     necessary to store nbits bits.  This is useful for copying bit strings.
52
53     The macros bit_clear() and bit_set() clear or set the zero-based numbered
54     bit bit, in the bit string name.
55
56     The bit_nset() and bit_nclear() macros set or clear the zero-based num‐
57     bered bits from start through stop in the bit string name.
58
59     The bit_test() macro evaluates to non-zero if the zero-based numbered bit
60     bit of bit string name is set, and zero otherwise.
61
62     The bit_ffs() macro stores in the location referenced by value the zero-
63     based number of the first bit set in the array of nbits bits referenced
64     by name.  If no bits are set, the location referenced by value is set to
65     -1.
66
67     The macro bit_ffc() stores in the location referenced by value the zero-
68     based number of the first bit not set in the array of nbits bits refer‐
69     enced by name.  If all bits are set, the location referenced by value is
70     set to -1.
71
72     The arguments to these macros are evaluated only once and may safely have
73     side effects.
74

EXAMPLES

76           #include <limits.h>
77           #include <bsd/bitstring.h>
78
79           ...
80           #define LPR_BUSY_BIT            0
81           #define LPR_FORMAT_BIT          1
82           #define LPR_DOWNLOAD_BIT        2
83           ...
84           #define LPR_AVAILABLE_BIT       9
85           #define LPR_MAX_BITS            10
86
87           make_lpr_available()
88           {
89                   bitstr_t bit_decl(bitlist, LPR_MAX_BITS);
90                   ...
91                   bit_nclear(bitlist, 0, LPR_MAX_BITS - 1);
92                   ...
93                   if (!bit_test(bitlist, LPR_BUSY_BIT)) {
94                           bit_clear(bitlist, LPR_FORMAT_BIT);
95                           bit_clear(bitlist, LPR_DOWNLOAD_BIT);
96                           bit_set(bitlist, LPR_AVAILABLE_BIT);
97                   }
98           }
99

SEE ALSO

101     malloc(3)
102

HISTORY

104     The bitstring functions first appeared in 4.4BSD.
105
106BSD                              July 19, 1993                             BSD
Impressum