1 .\" Copyright (c) 1989, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" This code is derived from software contributed to Berkeley by
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)bitstring.3 8.1 (Berkeley) 7/19/93
31 .\" $FreeBSD: src/share/man/man3/bitstring.3,v 1.6.2.5 2001/12/17 11:30:11 ru Exp $
32 .\" $DragonFly: src/share/man/man3/bitstring.3,v 1.2 2003/06/17 04:36:58 dillon Exp $
49 .Nd bit-string manipulation macros
53 .Fn bit_alloc "int nbits"
55 .Fn bit_decl "bitstr_t *name" "int nbits"
57 .Fn bit_clear "bitstr_t *name" "int bit"
59 .Fn bit_ffc "bitstr_t *name" "int nbits" "int *value"
61 .Fn bit_ffs "bitstr_t *name" "int nbits" "int *value"
63 .Fn bit_fls "bitstr_t *name" "int nbits" "int *value"
65 .Fn bit_nclear "bitstr_t *name" "int start" "int stop"
67 .Fn bit_nset "bitstr_t *name" "int start" "int stop"
69 .Fn bit_nsearch "bitstr_t *name" "int nbits" "int *value" "int len"
71 .Fn bit_set "bitstr_t *name" "int bit"
73 .Fn bitstr_size "int nbits"
75 .Fn bit_test "bitstr_t *name" "int bit"
77 These macros operate on strings of bits.
81 returns a pointer of type
83 to sufficient space to store
87 if no space is available.
91 allocates sufficient space to store
97 returns the number of elements of type
102 This is useful for copying bit strings.
108 clear or set the zero-based numbered bit
118 set or clear the zero-based numbered bits from
128 evaluates to non-zero if the zero-based numbered bit
132 is set, and zero otherwise.
137 stores in the location referenced by
139 the zero-based number of the first bit set in the array of
143 If no bits are set, the location referenced by
149 stores in the location referenced by
151 the zero-based number of the first bit not set in the array of
155 If all bits are set, the location referenced by
161 stores in the location referenced by
163 the zero-based number of the highest bit set in array of
170 stores in the location referenced by
172 the zero-based index of a span of clear bits of length
179 The arguments to these macros are evaluated only once and may safely
182 .Bd -literal -offset indent
184 #include <bitstring.h>
187 #define LPR_BUSY_BIT 0
188 #define LPR_FORMAT_BIT 1
189 #define LPR_DOWNLOAD_BIT 2
191 #define LPR_AVAILABLE_BIT 9
192 #define LPR_MAX_BITS 10
196 bitstr_t bit_decl(bitlist, LPR_MAX_BITS);
198 bit_nclear(bitlist, 0, LPR_MAX_BITS - 1);
200 if (!bit_test(bitlist, LPR_BUSY_BIT)) {
201 bit_clear(bitlist, LPR_FORMAT_BIT);
202 bit_clear(bitlist, LPR_DOWNLOAD_BIT);
203 bit_set(bitlist, LPR_AVAILABLE_BIT);
212 functions first appeared in
218 routines first appeared in