xref: /netbsd-src/share/man/man9/setbit.9 (revision 7bb35895510fee918b3c2b016f0ce1cd664675ea)
1.\" $NetBSD: setbit.9,v 1.3 2012/12/04 18:03:37 christos Exp $
2.\"
3.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Jukka Ruohonen.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE.
29.\"
30.Dd December 4, 2012
31.Dt SETBIT 9
32.Os
33.Sh NAME
34.Nm setbit
35.Nd macros related to bitmaps
36.Sh SYNOPSIS
37.In sys/param.h
38.Ft void
39.Fn setbit "array" "x"
40.Ft void
41.Fn clrbit "array" "x"
42.Ft int
43.Fn isset "array" "x"
44.Ft int
45.Fn isclr "array" "x"
46.Sh DESCRIPTION
47The
48.Nm
49family of macros operate with bitmaps, also known as bit arrays.
50.Pp
51In a nutshell,
52.Fn setbit
53sets the bit
54.Fa x
55in
56.Fa array ,
57.Fn clrbit
58clears it,
59.Fn isset
60tests whether
61.Fa x
62is set, and
63.Fn isclr
64returns 1 if
65.Fa x
66is not set.
67.Sh EXAMPLES
68The following example declares a buffer of 10 chars,
69treating it as an array of 80 bits:
70.Bd -literal -offset indent
71char buf[10];
72
73\&...
74
75setbit(buf, 12);	/* set the fifth bit in the second byte */
76.Ed
77.Sh SEE ALSO
78.Xr bitmap 3 ,
79.Xr bitstring 3
80.Sh CAVEATS
81The number of valid bits in a given array is assumed to be multiple of
82.Dv CHAR_BIT ,
83the number of bits for smallest object that is not a bit-field.
84