Updated: 2022/Sep/29

Please read Privacy Policy. It's for your privacy.

BITMAP(3)                  Library Functions Manual                  BITMAP(3)

     __BITMAP_ZERO - bitmap manipulation macros

     Standard C Library (libc, -lc)

     #include <sys/bitops.h>

     __BITMAP_CLR(int bit, type *bitmap);

     __BITMAP_ISSET(int bit, type *bitmap);

     __BITMAP_SET(int bit, type *bitmap);

     __BITMAP_SIZE(type, int nbits);

     __BITMAP_TYPE(name, type, int nbits);

     __BITMAP_ZERO(type *bitmap);

     The supplied macros are similar to the select(2) FD_SET() family, to the
     setbit(9), macros and the bitstring(3) library.  They are different from
     FD_SET() because they are designed to handle multiple sized bitmaps at
     the same time, and they can be of any integral type.  They are different
     from setbit(9) because they can operate on different integral types, not
     just on bytes.  They are different from bitstring(3) because they are
     just macros, they don't allocate memory or use code, and they can be used
     in both kernel and userland.

     The following macros are provided for manipulating creating and
     manipulating bitmaps:

     __BITMAP_CLR(bit, bitmap) removes the given bit from the bitmap.

     __BITMAP_ISSET(bit, bitmap) is non-zero if bit is a member of bitmap,
     zero otherwise.

     __BITMAP_SET(bit, bitmap) Sets the given bit in the bitmap.

     __BITMAP_SIZE(type, nbits) Returns the number of elements would be
     required of the given type to hold nbits.

     __BITMAP_TYPE(name, type, nbits) Declares the properly sized bitmap
     structure of the given type that holds nbits and is named name.

     __BITMAP_ZERO(bitmap) initializes a descriptor set pointed to by bitmap
     to the null set.

     The behavior of these macros is undefined for negative bit values or ones
     greater than the number of bits the bitmap can hold.

     #include <sys/bitops.h>

     main(int argc, char **argv)
             __BITMAP_TYPE(, uint32_t, 5000) bitmap;

             /* Initialize the read set to null */

             /* Set bit 1 */
             __BITMAP_SET(1, &bitmap);

             for (size_t i = 0; i < 5000; i++) {
                     if (__BITMAP_ISSET(i, &bitmap)) {
                             /* Should just print 1 */
                             printf("Bit %zu is set\n", i);
                             __BITMAP_CLR(i, &bitmap);
             return 0;

     select(2), bitops(3), bitstring(3), setbit(9)

     The __BITMAP_*() macros appeared in NetBSD 7.0.

NetBSD 10.99                     March 8, 2018                    NetBSD 10.99