1 .\" $NetBSD: bitstring.3,v 1.12 2004/11/10 16:36:28 wiz Exp $
3 .\" Copyright (c) 1989, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" This code is derived from software contributed to Berkeley by
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\" notice, this list of conditions and the following disclaimer in the
15 .\" documentation and/or other materials provided with the distribution.
16 .\" 3. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" @(#)bitstring.3 8.1 (Berkeley) 7/19/93
48 .Nd bit-string manipulation macros
52 .Fn bit_alloc "int nbits"
53 .Fn bit_clear "bit_str name" "int bit"
54 .Fn bit_decl "bit_str name" "int nbits"
55 .Fn bit_ffc "bit_str name" "int nbits" "int *value"
56 .Fn bit_ffs "bit_str name" "int nbits" "int *value"
57 .Fn bit_nclear "bit_str name" "int start" "int stop"
58 .Fn bit_nset "bit_str name" "int start" "int stop"
59 .Fn bit_set "bit_str name" "int bit"
60 .Fn bitstr_size "int nbits"
61 .Fn bit_test "bit_str name" "int bit"
63 These macros operate on strings of bits.
67 returns a pointer of type
69 to sufficient space to store
73 if no space is available.
77 allocates sufficient space to store
83 returns the number of elements of type
88 This is useful for copying bit strings.
94 clear or set the zero-based numbered bit
104 set or clear the zero-based numbered bits from
114 evaluates to non-zero if the zero-based numbered bit
118 is set, and zero otherwise.
123 stores in the location referenced by
125 the zero-based number of the first bit set in the array of
129 If no bits are set, the location referenced by
135 stores in the location referenced by
137 the zero-based number of the first bit not set in the array of
141 If all bits are set, the location referenced by
145 The arguments to these macros are evaluated only once and may safely
148 .Bd -literal -offset indent
149 #include \*[Lt]limits.h\*[Gt]
150 #include \*[Lt]bitstring.h\*[Gt]
153 #define LPR_BUSY_BIT 0
154 #define LPR_FORMAT_BIT 1
155 #define LPR_DOWNLOAD_BIT 2
157 #define LPR_AVAILABLE_BIT 9
158 #define LPR_MAX_BITS 10
162 bitstr_t bit_decl(bitlist, LPR_MAX_BITS);
164 bit_nclear(bitlist, 0, LPR_MAX_BITS - 1);
166 if (!bit_test(bitlist, LPR_BUSY_BIT)) {
167 bit_clear(bitlist, LPR_FORMAT_BIT);
168 bit_clear(bitlist, LPR_DOWNLOAD_BIT);
169 bit_set(bitlist, LPR_AVAILABLE_BIT);
178 functions first appeared in