1afe61c15SRodney W. Grimes.\" Copyright (c) 1989, 1991, 1993 2afe61c15SRodney W. Grimes.\" The Regents of the University of California. All rights reserved. 3afe61c15SRodney W. Grimes.\" 4afe61c15SRodney W. Grimes.\" This code is derived from software contributed to Berkeley by 5afe61c15SRodney W. Grimes.\" Paul Vixie. 6afe61c15SRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without 7afe61c15SRodney W. Grimes.\" modification, are permitted provided that the following conditions 8afe61c15SRodney W. Grimes.\" are met: 9afe61c15SRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright 10afe61c15SRodney W. Grimes.\" notice, this list of conditions and the following disclaimer. 11afe61c15SRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright 12afe61c15SRodney W. Grimes.\" notice, this list of conditions and the following disclaimer in the 13afe61c15SRodney W. Grimes.\" documentation and/or other materials provided with the distribution. 14dda5b397SEitan Adler.\" 3. Neither the name of the University nor the names of its contributors 15afe61c15SRodney W. Grimes.\" may be used to endorse or promote products derived from this software 16afe61c15SRodney W. Grimes.\" without specific prior written permission. 17afe61c15SRodney W. Grimes.\" 18afe61c15SRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19afe61c15SRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20afe61c15SRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21afe61c15SRodney W. Grimes.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22afe61c15SRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23afe61c15SRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24afe61c15SRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25afe61c15SRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26afe61c15SRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27afe61c15SRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28afe61c15SRodney W. Grimes.\" SUCH DAMAGE. 29afe61c15SRodney W. Grimes.\" 301b82e02fSAlan Somers.\" Copyright (c) 2014,2016 Spectra Logic Corporation 318907f744SAlan Somers.\" All rights reserved. 328907f744SAlan Somers.\" 338907f744SAlan Somers.\" Redistribution and use in source and binary forms, with or without 348907f744SAlan Somers.\" modification, are permitted provided that the following conditions 358907f744SAlan Somers.\" are met: 368907f744SAlan Somers.\" 1. Redistributions of source code must retain the above copyright 378907f744SAlan Somers.\" notice, this list of conditions, and the following disclaimer, 388907f744SAlan Somers.\" without modification. 398907f744SAlan Somers.\" 2. Redistributions in binary form must reproduce at minimum a disclaimer 408907f744SAlan Somers.\" substantially similar to the "NO WARRANTY" disclaimer below 418907f744SAlan Somers.\" ("Disclaimer") and any redistribution must be conditioned upon 428907f744SAlan Somers.\" including a substantially similar Disclaimer requirement for further 438907f744SAlan Somers.\" binary redistribution. 448907f744SAlan Somers.\" 458907f744SAlan Somers.\" NO WARRANTY 468907f744SAlan Somers.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 478907f744SAlan Somers.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 488907f744SAlan Somers.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 498907f744SAlan Somers.\" A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 508907f744SAlan Somers.\" HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 518907f744SAlan Somers.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 528907f744SAlan Somers.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 538907f744SAlan Somers.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 548907f744SAlan Somers.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 558907f744SAlan Somers.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 568907f744SAlan Somers.\" POSSIBILITY OF SUCH DAMAGES. 578907f744SAlan Somers.\" 58afe61c15SRodney W. Grimes.\" @(#)bitstring.3 8.1 (Berkeley) 7/19/93 597f3dea24SPeter Wemm.\" $FreeBSD$ 60afe61c15SRodney W. Grimes.\" 6114a4d6d0SVladimir Kondratyev.Dd August 8, 2021 62afe61c15SRodney W. Grimes.Dt BITSTRING 3 633d45e180SRuslan Ermilov.Os 64afe61c15SRodney W. Grimes.Sh NAME 65afe61c15SRodney W. Grimes.Nm bit_alloc , 66afe61c15SRodney W. Grimes.Nm bit_clear , 671b82e02fSAlan Somers.Nm bit_count , 68afe61c15SRodney W. Grimes.Nm bit_decl , 698907f744SAlan Somers.Nm bit_ffc , 70afe61c15SRodney W. Grimes.Nm bit_ffs , 71*84e2ae64SDoug Moore.Nm bit_ff_at , 728907f744SAlan Somers.Nm bit_ffc_at , 738907f744SAlan Somers.Nm bit_ffs_at , 7452e8f6a3SEric Joyner.Nm bit_ffc_area , 7552e8f6a3SEric Joyner.Nm bit_ffs_area , 76*84e2ae64SDoug Moore.Nm bit_ff_area_at , 7752e8f6a3SEric Joyner.Nm bit_ffc_area_at , 7852e8f6a3SEric Joyner.Nm bit_ffs_area_at , 79afe61c15SRodney W. Grimes.Nm bit_nclear , 80afe61c15SRodney W. Grimes.Nm bit_nset , 81*84e2ae64SDoug Moore.Nm bit_ntest , 82afe61c15SRodney W. Grimes.Nm bit_set , 838907f744SAlan Somers.Nm bit_test , 848907f744SAlan Somers.Nm bitstr_size 858907f744SAlan Somers.Nd bit-string manipulation functions and macros 86afe61c15SRodney W. Grimes.Sh SYNOPSIS 8732eef9aeSRuslan Ermilov.In bitstring.h 88afe61c15SRodney W. Grimes.Ft bitstr_t * 89afe61c15SRodney W. Grimes.Fn bit_alloc "int nbits" 9069a6a1d7SBruce Evans.Ft void 9169a6a1d7SBruce Evans.Fn bit_decl "bitstr_t *name" "int nbits" 9269a6a1d7SBruce Evans.Ft void 9369a6a1d7SBruce Evans.Fn bit_clear "bitstr_t *name" "int bit" 9469a6a1d7SBruce Evans.Ft void 951b82e02fSAlan Somers.Fn bit_count "bitstr_t *name" "int count" "int nbits" "int *value" 961b82e02fSAlan Somers.Ft void 9769a6a1d7SBruce Evans.Fn bit_ffc "bitstr_t *name" "int nbits" "int *value" 9869a6a1d7SBruce Evans.Ft void 9969a6a1d7SBruce Evans.Fn bit_ffs "bitstr_t *name" "int nbits" "int *value" 10069a6a1d7SBruce Evans.Ft void 1018907f744SAlan Somers.Fn bit_ffc_at "bitstr_t *name" "int start" "int nbits" "int *value" 1028907f744SAlan Somers.Ft void 1038907f744SAlan Somers.Fn bit_ffs_at "bitstr_t *name" "int start" "int nbits" "int *value" 1048907f744SAlan Somers.Ft void 105*84e2ae64SDoug Moore.Fn bit_ff_at "bitstr_t *name" "int start" "int nbits" "int match" "int *value" 106*84e2ae64SDoug Moore.Ft void 10752e8f6a3SEric Joyner.Fn bit_ffc_area "bitstr_t *name" "int nbits" "int size" "int *value" 10852e8f6a3SEric Joyner.Ft void 10952e8f6a3SEric Joyner.Fn bit_ffs_area "bitstr_t *name" "int nbits" "int size" "int *value" 11052e8f6a3SEric Joyner.Ft void 11152e8f6a3SEric Joyner.Fn bit_ffc_area_at "bitstr_t *name" "int start" "int nbits" "int size" "int *value" 11252e8f6a3SEric Joyner.Ft void 11352e8f6a3SEric Joyner.Fn bit_ffs_area_at "bitstr_t *name" "int start" "int nbits" "int size" "int *value" 114*84e2ae64SDoug Moore.Ft void 115*84e2ae64SDoug Moore.Fn bit_ff_area_at "bitstr_t *name" "int start" "int nbits" "int size" "int match" "int *value" 11614a4d6d0SVladimir Kondratyev.Fn bit_foreach "bitstr_t *name" "int nbits" "int var" 11714a4d6d0SVladimir Kondratyev.Fn bit_foreach_at "bitstr_t *name" "int start" "int nbits" "int var" 11814a4d6d0SVladimir Kondratyev.Fn bit_foreach_unset "bitstr_t *name" "int nbits" "int var" 11914a4d6d0SVladimir Kondratyev.Fn bit_foreach_unset_at "bitstr_t *name" "int start" "int nbits" "int var" 12052e8f6a3SEric Joyner.Ft void 12169a6a1d7SBruce Evans.Fn bit_nclear "bitstr_t *name" "int start" "int stop" 12269a6a1d7SBruce Evans.Ft void 12369a6a1d7SBruce Evans.Fn bit_nset "bitstr_t *name" "int start" "int stop" 124*84e2ae64SDoug Moore.Ft int 125*84e2ae64SDoug Moore.Fn bit_ntest "bitstr_t *name" "int start" "int stop" "int match" 12669a6a1d7SBruce Evans.Ft void 12769a6a1d7SBruce Evans.Fn bit_set "bitstr_t *name" "int bit" 12869a6a1d7SBruce Evans.Ft int 129afe61c15SRodney W. Grimes.Fn bitstr_size "int nbits" 13069a6a1d7SBruce Evans.Ft int 13169a6a1d7SBruce Evans.Fn bit_test "bitstr_t *name" "int bit" 132afe61c15SRodney W. Grimes.Sh DESCRIPTION 133afe61c15SRodney W. GrimesThese macros operate on strings of bits. 134afe61c15SRodney W. Grimes.Pp 1358907f744SAlan SomersThe function 136afe61c15SRodney W. Grimes.Fn bit_alloc 137afe61c15SRodney W. Grimesreturns a pointer of type 138afe61c15SRodney W. Grimes.Dq Fa "bitstr_t *" 139afe61c15SRodney W. Grimesto sufficient space to store 140afe61c15SRodney W. Grimes.Fa nbits 141afe61c15SRodney W. Grimesbits, or 142afe61c15SRodney W. Grimes.Dv NULL 143afe61c15SRodney W. Grimesif no space is available. 1448907f744SAlan SomersIf successful, the returned bit string is initialized with all bits cleared. 145afe61c15SRodney W. Grimes.Pp 146afe61c15SRodney W. GrimesThe macro 147afe61c15SRodney W. Grimes.Fn bit_decl 1488907f744SAlan Somersdeclares a bit string with sufficient space to store 149afe61c15SRodney W. Grimes.Fa nbits 1508907f744SAlan Somersbits. 1518907f744SAlan Somers.Fn bit_decl 1528907f744SAlan Somersmay be used to include statically sized bit strings in structure 1538907f744SAlan Somersdefinitions or to create bit strings on the stack. 1548907f744SAlan SomersUsers of this macro are responsible for initialization of the bit string, 1558907f744SAlan Somerstypically via a global initialization of the containing struct or use of the 1568907f744SAlan Somers.Fn bit_nset 1578907f744SAlan Somersor 1588907f744SAlan Somers.Fn bin_nclear 1598907f744SAlan Somersfunctions. 160afe61c15SRodney W. Grimes.Pp 161afe61c15SRodney W. GrimesThe macro 162afe61c15SRodney W. Grimes.Fn bitstr_size 1638907f744SAlan Somersreturns the number of bytes necessary to store 164afe61c15SRodney W. Grimes.Fa nbits 165afe61c15SRodney W. Grimesbits. 166afe61c15SRodney W. GrimesThis is useful for copying bit strings. 167afe61c15SRodney W. Grimes.Pp 1688907f744SAlan SomersThe functions 169afe61c15SRodney W. Grimes.Fn bit_clear 170afe61c15SRodney W. Grimesand 171afe61c15SRodney W. Grimes.Fn bit_set 172afe61c15SRodney W. Grimesclear or set the zero-based numbered bit 173afe61c15SRodney W. Grimes.Fa bit , 174afe61c15SRodney W. Grimesin the bit string 175afe61c15SRodney W. Grimes.Ar name . 176afe61c15SRodney W. Grimes.Pp 177afe61c15SRodney W. GrimesThe 178afe61c15SRodney W. Grimes.Fn bit_nset 179afe61c15SRodney W. Grimesand 180afe61c15SRodney W. Grimes.Fn bit_nclear 1818907f744SAlan Somersfunctions 182afe61c15SRodney W. Grimesset or clear the zero-based numbered bits from 183afe61c15SRodney W. Grimes.Fa start 1840b607240SJohn-Mark Gurneythrough 185afe61c15SRodney W. Grimes.Fa stop 186afe61c15SRodney W. Grimesin the bit string 187afe61c15SRodney W. Grimes.Ar name . 188afe61c15SRodney W. Grimes.Pp 189afe61c15SRodney W. GrimesThe 190afe61c15SRodney W. Grimes.Fn bit_test 1918907f744SAlan Somersfunction 192afe61c15SRodney W. Grimesevaluates to non-zero if the zero-based numbered bit 193afe61c15SRodney W. Grimes.Fa bit 194afe61c15SRodney W. Grimesof bit string 195afe61c15SRodney W. Grimes.Fa name 196afe61c15SRodney W. Grimesis set, and zero otherwise. 197afe61c15SRodney W. Grimes.Pp 198*84e2ae64SDoug MooreThe 199*84e2ae64SDoug Moore.Fn bit_ntest 200*84e2ae64SDoug Moorefunction 201*84e2ae64SDoug Mooreevaluates to non-zero if the zero-based numbered bits from 202*84e2ae64SDoug Moore.Fa start 203*84e2ae64SDoug Moorethrough 204*84e2ae64SDoug Moore.Fa stop 205*84e2ae64SDoug Moorein the bit string 206*84e2ae64SDoug Moore.Ar name 207*84e2ae64SDoug Mooreall have the value 208*84e2ae64SDoug Moore.Ar match . 209*84e2ae64SDoug Moore.Pp 2108907f744SAlan SomersThe function 211afe61c15SRodney W. Grimes.Fn bit_ffc 212afe61c15SRodney W. Grimesstores in the location referenced by 213afe61c15SRodney W. Grimes.Fa value 214afe61c15SRodney W. Grimesthe zero-based number of the first bit not set in the array of 215afe61c15SRodney W. Grimes.Fa nbits 216afe61c15SRodney W. Grimesbits referenced by 217afe61c15SRodney W. Grimes.Fa name . 218afe61c15SRodney W. GrimesIf all bits are set, the location referenced by 219afe61c15SRodney W. Grimes.Fa value 220afe61c15SRodney W. Grimesis set to \-1. 221afe61c15SRodney W. Grimes.Pp 2228907f744SAlan SomersThe 2238907f744SAlan Somers.Fn bit_ffs 2248907f744SAlan Somersfunction 2258907f744SAlan Somersstores in the location referenced by 2268907f744SAlan Somers.Fa value 2278907f744SAlan Somersthe zero-based number of the first bit set in the array of 2288907f744SAlan Somers.Fa nbits 2298907f744SAlan Somersbits referenced by 2308907f744SAlan Somers.Fa name . 2318907f744SAlan SomersIf no bits are set, the location referenced by 2328907f744SAlan Somers.Fa value 2338907f744SAlan Somersis set to \-1. 2348907f744SAlan Somers.Pp 2358907f744SAlan SomersThe function 2368907f744SAlan Somers.Fn bit_ffc_at 2378907f744SAlan Somersstores in the location referenced by 2388907f744SAlan Somers.Fa value 2398907f744SAlan Somersthe zero-based number of the first bit not set in the array of 2408907f744SAlan Somers.Fa nbits 2418907f744SAlan Somersbits referenced by 2428907f744SAlan Somers.Fa name , 2438907f744SAlan Somersat or after the zero-based bit index 2448907f744SAlan Somers.Fa start . 2458907f744SAlan SomersIf all bits at or after 2468907f744SAlan Somers.Fa start 2478907f744SAlan Somersare set, the location referenced by 2488907f744SAlan Somers.Fa value 2498907f744SAlan Somersis set to \-1. 2508907f744SAlan Somers.Pp 2518907f744SAlan SomersThe 2528907f744SAlan Somers.Fn bit_ffs_at 2538907f744SAlan Somersfunction 2548907f744SAlan Somersstores in the location referenced by 2558907f744SAlan Somers.Fa value 2568907f744SAlan Somersthe zero-based number of the first bit set in the array of 2578907f744SAlan Somers.Fa nbits 2588907f744SAlan Somersbits referenced by 2598907f744SAlan Somers.Fa name , 2608907f744SAlan Somersat or after the zero-based bit index 2618907f744SAlan Somers.Fa start . 2628907f744SAlan SomersIf no bits are set after 2638907f744SAlan Somers.Fa start , 2648907f744SAlan Somersthe location referenced by 2658907f744SAlan Somers.Fa value 2668907f744SAlan Somersis set to \-1. 2678907f744SAlan Somers.Pp 2681b82e02fSAlan SomersThe 269*84e2ae64SDoug Moore.Fn bit_ff_at 270*84e2ae64SDoug Moorefunction 271*84e2ae64SDoug Moorestores in the location referenced by 272*84e2ae64SDoug Moore.Fa value 273*84e2ae64SDoug Moorethe zero-based number of the first bit in the array of 274*84e2ae64SDoug Moore.Fa nbits 275*84e2ae64SDoug Moorebits referenced by 276*84e2ae64SDoug Moore.Fa name , 277*84e2ae64SDoug Mooreat or after the zero-based bit index 278*84e2ae64SDoug Moore.Fa start 279*84e2ae64SDoug Moorethat has value 280*84e2ae64SDoug Moore.Fa match . 281*84e2ae64SDoug MooreIf no bits after 282*84e2ae64SDoug Moore.Fa start 283*84e2ae64SDoug Moorematch that value, the location referenced by 284*84e2ae64SDoug Moore.Fa value 285*84e2ae64SDoug Mooreis set to \-1. 286*84e2ae64SDoug Moore.Pp 287*84e2ae64SDoug MooreThe 28852e8f6a3SEric Joyner.Fn bit_ffc_area 28952e8f6a3SEric Joynerfunction stores in the location referenced by 29052e8f6a3SEric Joyner.Fa value 29152e8f6a3SEric Joynerthe zero-based number of the first bit beginning a sequence of unset bits of 29252e8f6a3SEric Joynerat least 29352e8f6a3SEric Joyner.Fa size 29452e8f6a3SEric Joynerunset bits in the array of 29552e8f6a3SEric Joyner.Fa nbits 29652e8f6a3SEric Joynerbits referenced by 29752e8f6a3SEric Joyner.Fa name . 29852e8f6a3SEric JoynerIf no sequence of contiguous unset bits of the specified 29952e8f6a3SEric Joyner.Fa size 30052e8f6a3SEric Joynercan be found, the location referenced by 30152e8f6a3SEric Joyner.Fa value 30252e8f6a3SEric Joyneris set to \-1. 30352e8f6a3SEric Joyner.Pp 30452e8f6a3SEric JoynerThe 30552e8f6a3SEric Joyner.Fn bit_ffs_area 30652e8f6a3SEric Joynerfunction stores in the location referenced by 30752e8f6a3SEric Joyner.Fa value 30852e8f6a3SEric Joynerthe zero-based number of the first bit beginning a sequence of set bits of 30952e8f6a3SEric Joynerat least 31052e8f6a3SEric Joyner.Fa size 31152e8f6a3SEric Joynerset bits in the array of 31252e8f6a3SEric Joyner.Fa nbits 31352e8f6a3SEric Joynerbits referenced by 31452e8f6a3SEric Joyner.Fa name . 31552e8f6a3SEric JoynerIf no sequence of contiguous set bits of the specified 31652e8f6a3SEric Joyner.Fa size 31752e8f6a3SEric Joynercan be found, the location referenced by 31852e8f6a3SEric Joyner.Fa value 31952e8f6a3SEric Joyneris set to \-1. 32052e8f6a3SEric Joyner.Pp 32152e8f6a3SEric JoynerThe 32252e8f6a3SEric Joyner.Fn bit_ffc_area_at 32352e8f6a3SEric Joynerfunction stores in the location referenced by 32452e8f6a3SEric Joyner.Fa value 32552e8f6a3SEric Joynerthe zero-based number of the first bit beginning a sequence of unset bits of 32652e8f6a3SEric Joynerat least 32752e8f6a3SEric Joyner.Fa size 32852e8f6a3SEric Joynerunset bits in the array of 32952e8f6a3SEric Joyner.Fa nbits 33052e8f6a3SEric Joynerbits referenced by 33152e8f6a3SEric Joyner.Fa name , 33252e8f6a3SEric Joynerat or after the zero-based bit index 33352e8f6a3SEric Joyner.Fa start . 33452e8f6a3SEric JoynerIf no sequence of contiguous unset bits of the specified 33552e8f6a3SEric Joyner.Fa size 33652e8f6a3SEric Joynercan be found at or after 33752e8f6a3SEric Joyner.Fa start , 33852e8f6a3SEric Joynerthe location referenced by 33952e8f6a3SEric Joyner.Fa value 34052e8f6a3SEric Joyneris set to \-1. 34152e8f6a3SEric Joyner.Pp 34252e8f6a3SEric JoynerThe 34352e8f6a3SEric Joyner.Fn bit_ffs_area_at 34452e8f6a3SEric Joynerfunction stores in the location referenced by 34552e8f6a3SEric Joyner.Fa value 34652e8f6a3SEric Joynerthe zero-based number of the first bit beginning a sequence of set bits of 34752e8f6a3SEric Joynerat least 34852e8f6a3SEric Joyner.Fa size 34952e8f6a3SEric Joynerset bits in the array of 35052e8f6a3SEric Joyner.Fa nbits 35152e8f6a3SEric Joynerbits referenced by 35252e8f6a3SEric Joyner.Fa name , 35352e8f6a3SEric Joynerat or after the zero-based bit index 35452e8f6a3SEric Joyner.Fa start . 35552e8f6a3SEric JoynerIf no sequence of contiguous set bits of the specified 35652e8f6a3SEric Joyner.Fa size 35752e8f6a3SEric Joynercan be found at or after 35852e8f6a3SEric Joyner.Fa start , 35952e8f6a3SEric Joynerthe location referenced by 36052e8f6a3SEric Joyner.Fa value 36152e8f6a3SEric Joyneris set to \-1. 36252e8f6a3SEric Joyner.Pp 36352e8f6a3SEric JoynerThe 364*84e2ae64SDoug Moore.Fn bit_ff_area_at 365*84e2ae64SDoug Moorefunction stores in the location referenced by 366*84e2ae64SDoug Moore.Fa value 367*84e2ae64SDoug Moorethe zero-based number of the first bit beginning a sequence of bits of 368*84e2ae64SDoug Mooreat least 369*84e2ae64SDoug Moore.Fa size 370*84e2ae64SDoug Moorebits in the array of 371*84e2ae64SDoug Moore.Fa nbits 372*84e2ae64SDoug Moorebits referenced by 373*84e2ae64SDoug Moore.Fa name , 374*84e2ae64SDoug Mooreat or after the zero-based bit index 375*84e2ae64SDoug Moore.Fa start 376*84e2ae64SDoug Moorein which all bits have the value 377*84e2ae64SDoug Moore.Fa match . 378*84e2ae64SDoug MooreIf no sequence of contiguous such bits of the specified 379*84e2ae64SDoug Moore.Fa size 380*84e2ae64SDoug Moorecan be found at or after 381*84e2ae64SDoug Moore.Fa start , 382*84e2ae64SDoug Moorethe location referenced by 383*84e2ae64SDoug Moore.Fa value 384*84e2ae64SDoug Mooreis set to \-1. 385*84e2ae64SDoug Moore.Pp 386*84e2ae64SDoug MooreThe 3871b82e02fSAlan Somers.Fn bit_count 3881b82e02fSAlan Somersfunction stores in the location referenced by 3891b82e02fSAlan Somers.Fa value 3901b82e02fSAlan Somersthe number of bits set in the array of 3911b82e02fSAlan Somers.Fa nbits 3921b82e02fSAlan Somersbits referenced by 3931b82e02fSAlan Somers.Fa name , 3941b82e02fSAlan Somersat or after the zero-based bit index 3951b82e02fSAlan Somers.Fa start . 3961b82e02fSAlan Somers.Pp 39714a4d6d0SVladimir KondratyevThe macro 39814a4d6d0SVladimir Kondratyev.Fn bit_foreach 39914a4d6d0SVladimir Kondratyevtraverses all set bits in the array of 40014a4d6d0SVladimir Kondratyev.Fa nbits 40114a4d6d0SVladimir Kondratyevreferenced by 40214a4d6d0SVladimir Kondratyev.Fa name 40314a4d6d0SVladimir Kondratyevin the forward direction, assigning each location in turn to 40414a4d6d0SVladimir Kondratyev.Fa var . 40514a4d6d0SVladimir Kondratyev.Pp 40614a4d6d0SVladimir KondratyevThe macro 40714a4d6d0SVladimir Kondratyev.Fn bit_foreach_at 40814a4d6d0SVladimir Kondratyevtraverses all set bits in the array of 40914a4d6d0SVladimir Kondratyev.Fa nbits 41014a4d6d0SVladimir Kondratyevreferenced by 41114a4d6d0SVladimir Kondratyev.Fa name 41214a4d6d0SVladimir Kondratyevin the forward direction at or after the zero-based bit index 41314a4d6d0SVladimir Kondratyev.Fa start , 41414a4d6d0SVladimir Kondratyevassigning each location in turn to 41514a4d6d0SVladimir Kondratyev.Fa var . 41614a4d6d0SVladimir Kondratyev.Pp 41714a4d6d0SVladimir KondratyevThe macro 41814a4d6d0SVladimir Kondratyev.Fn bit_foreach_unset 41914a4d6d0SVladimir Kondratyevtraverses all unset bits in the array of 42014a4d6d0SVladimir Kondratyev.Fa nbits 42114a4d6d0SVladimir Kondratyevreferenced by 42214a4d6d0SVladimir Kondratyev.Fa name 42314a4d6d0SVladimir Kondratyevin the forward direction, assigning each location in turn to 42414a4d6d0SVladimir Kondratyev.Fa var . 42514a4d6d0SVladimir Kondratyev.Pp 42614a4d6d0SVladimir KondratyevThe macro 42714a4d6d0SVladimir Kondratyev.Fn bit_foreach_unset_at 42814a4d6d0SVladimir Kondratyevtraverses all unset bits in the array of 42914a4d6d0SVladimir Kondratyev.Fa nbits 43014a4d6d0SVladimir Kondratyevreferenced by 43114a4d6d0SVladimir Kondratyev.Fa name 43214a4d6d0SVladimir Kondratyevin the forward direction at or after the zero-based bit index 43314a4d6d0SVladimir Kondratyev.Fa start , 43414a4d6d0SVladimir Kondratyevassigning each location in turn to 43514a4d6d0SVladimir Kondratyev.Fa var . 43614a4d6d0SVladimir Kondratyev.Pp 4378907f744SAlan SomersThe arguments in bit string macros are evaluated only once and may safely 438afe61c15SRodney W. Grimeshave side effects. 439251c176fSRuslan Ermilov.Sh EXAMPLES 440afe61c15SRodney W. Grimes.Bd -literal -offset indent 441afe61c15SRodney W. Grimes#include <limits.h> 442afe61c15SRodney W. Grimes#include <bitstring.h> 443afe61c15SRodney W. Grimes 4443136363fSRuslan Ermilov\&... 445afe61c15SRodney W. Grimes#define LPR_BUSY_BIT 0 446afe61c15SRodney W. Grimes#define LPR_FORMAT_BIT 1 447afe61c15SRodney W. Grimes#define LPR_DOWNLOAD_BIT 2 4483136363fSRuslan Ermilov\&... 449afe61c15SRodney W. Grimes#define LPR_AVAILABLE_BIT 9 450afe61c15SRodney W. Grimes#define LPR_MAX_BITS 10 451afe61c15SRodney W. Grimes 452afe61c15SRodney W. Grimesmake_lpr_available() 453afe61c15SRodney W. Grimes{ 454afe61c15SRodney W. Grimes bitstr_t bit_decl(bitlist, LPR_MAX_BITS); 455afe61c15SRodney W. Grimes ... 456afe61c15SRodney W. Grimes bit_nclear(bitlist, 0, LPR_MAX_BITS - 1); 457afe61c15SRodney W. Grimes ... 458afe61c15SRodney W. Grimes if (!bit_test(bitlist, LPR_BUSY_BIT)) { 459afe61c15SRodney W. Grimes bit_clear(bitlist, LPR_FORMAT_BIT); 460afe61c15SRodney W. Grimes bit_clear(bitlist, LPR_DOWNLOAD_BIT); 461afe61c15SRodney W. Grimes bit_set(bitlist, LPR_AVAILABLE_BIT); 462afe61c15SRodney W. Grimes } 463afe61c15SRodney W. Grimes} 464afe61c15SRodney W. Grimes.Ed 465afe61c15SRodney W. Grimes.Sh SEE ALSO 4667ebf4122SConrad Meyer.Xr malloc 3 , 4677ebf4122SConrad Meyer.Xr bitset 9 468afe61c15SRodney W. Grimes.Sh HISTORY 469afe61c15SRodney W. GrimesThe 470afe61c15SRodney W. Grimes.Nm bitstring 47121421932SMike Pritchardfunctions first appeared in 47221421932SMike Pritchard.Bx 4.4 . 473