xref: /386bsd/usr/share/man/cat3/bitstring.0 (revision a2142627)
1BITSTRING(3)              386BSD Programmer's Manual              BITSTRING(3)
2
3NNAAMMEE
4     bbiitt__aalllloocc, bbiitt__cclleeaarr, bbiitt__ddeeccll, bbiitt__ffffss, bbiitt__nncclleeaarr, bbiitt__nnsseett,, bbiitt__sseett,
5     bbiittssttrr__ssiizzee, bbiitt__tteesstt - bit-string manipulation macros
6
7SSYYNNOOPPSSIISS
8     ##iinncclluuddee <<bbiittssttrriinngg..hh>>
9
10     _b_i_t_s_t_r__t *
11     bbiitt__aalllloocc(_i_n_t _n_b_i_t_s)
12
13     bbiitt__ddeeccll(_b_i_t__s_t_r _n_a_m_e, _i_n_t _n_b_i_t_s)
14
15     bbiitt__cclleeaarr(_b_i_t__s_t_r _n_a_m_e, _i_n_t _b_i_t)
16
17     bbiitt__ffffcc(_b_i_t__s_t_r _n_a_m_e, _i_n_t _n_b_i_t_s, _i_n_t *_v_a_l_u_e)
18
19     bbiitt__ffffss(_b_i_t__s_t_r _n_a_m_e, _i_n_t _n_b_i_t_s, _i_n_t *_v_a_l_u_e)
20
21     bbiitt__nncclleeaarr(_b_i_t__s_t_r _n_a_m_e, _i_n_t _s_t_a_r_t, _i_n_t _s_t_o_p)
22
23     bbiitt__nnsseett(_b_i_t__s_t_r _n_a_m_e, _i_n_t _s_t_a_r_t, _i_n_t _s_t_o_p)
24
25     bbiitt__sseett(_b_i_t__s_t_r _n_a_m_e, _i_n_t _b_i_t)
26
27     bbiittssttrr__ssiizzee(_i_n_t _n_b_i_t_s)
28
29     bbiitt__tteesstt(_b_i_t__s_t_r _n_a_m_e, _i_n_t _b_i_t)
30
31DDEESSCCRRIIPPTTIIOONN
32     These macros operate on strings of bits.
33
34     The macro bbiitt__aalllloocc() returns a pointer of type ``_b_i_t_s_t_r__t *'' to suffi-
35     cient space to store _n_b_i_t_s bits, or NULL if no space is available.
36
37     The macro bbiitt__ddeeccll() allocates sufficient space to store _n_b_i_t_s bits on
38     the stack.
39
40     The macro bbiittssttrr__ssiizzee() returns the number of elements of type _b_i_t_s_t_r__t
41     necessary to store _n_b_i_t_s bits.  This is useful for copying bit strings.
42
43     The macros bbiitt__cclleeaarr() and bbiitt__sseett() clear or set the zero-based numbered
44     bit _b_i_t, in the bit string _n_a_m_e.
45
46     The bbiitt__nnsseett() and bbiitt__nncclleeaarr() macros set or clear the zero-based num-
47     bered bits from _s_t_a_r_t to _s_t_o_p in the bit string _n_a_m_e.
48
49     The bbiitt__tteesstt() macro evaluates to zero if the zero-based numbered bit _b_i_t
50     of bit string _n_a_m_e is set, and non-zero otherwise.
51
52     The bbiitt__ffffss() macro stores in the location referenced by _v_a_l_u_e the zero-
53     based number of the first bit set in the array of _n_b_i_t_s bits referenced
54     by _n_a_m_e. If no bits are set, the location referenced by _v_a_l_u_e is set to
55     -1.
56
57     The macro bbiitt__ffffcc() stores in the location referenced by _v_a_l_u_e the zero-
58     based number of the first bit not set in the array of _n_b_i_t_s bits refer-
59     enced by _n_a_m_e. If all bits are set, the location referenced by _v_a_l_u_e is
60     set to -1.
61
62     The arguments to these macros are evaluated only once and may safely have
63     side effects.
64
65EEXXAAMMPPLLEE
66           #include <limits.h>
67           #include <bitstring.h>
68
69           #define LPR_BUSY_BIT            0
70           #define LPR_FORMAT_BIT          1
71           #define LPR_DOWNLOAD_BIT        2
72           #define LPR_AVAILABLE_BIT       9
73           #define LPR_MAX_BITS            10
74
75           make_lpr_available()
76           {
77                   bitstr_t bit_decl(bitlist, LPR_MAX_BITS);
78                   ...
79                   bit_nclear(bitlist, 0, LPR_MAX_BITS - 1);
80                   ...
81                   if (!bit_test(bitlist, LPR_BUSY_BIT)) {
82                           bit_clear(bitlist, LPR_FORMAT_BIT);
83                           bit_clear(bitlist, LPR_DOWNLOAD_BIT);
84                           bit_set(bitlist, LPR_AVAILABLE_BIT);
85                   }
86           }
87
88SSEEEE AALLSSOO
89     malloc(3)
90
91HHIISSTTOORRYY
92     The bbiitt__aalllloocc functions are currently under development.
93
944th Berkeley Distribution       April 19, 1991                               3
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133