SETBIT(9)
okay so you clicked into setbit(9) β the Kernel Developer's Manual page β and honestly? iconic. This is the group chat for the setbit family of macros, aka the bitmap besties π
β¨
π NAME π
setbit β macros related to bitmaps π
β¨ SYNOPSIS β¨
First, pull in the header like the good little kernel gremlin you are:
#include <sys/param.h>
Then the whole squad shows up:
void
setbit(array, x);
void
clrbit(array, x);
int
isset(array, x);
int
isclr(array, x);
π¦ DESCRIPTION π¦
The setbit family of macros operate with bitmaps, also known as bit arrays. No cap, that's the whole vibe π«Ά
In a nutshell: setbit() sets the bit x in array; clrbit() clears it; isset() tests whether x is set; and isclr() returns 1 if x is not set. Slay, concise king πβ¨
πΈ EXAMPLES πΈ
Here's the example, bestie: a buffer of 10 chars gets treated as an array of 80 bits:
char buf[10];
...
setbit(buf, 12); /* set the fifth bit in the second byte */
That comment is literally doing the most and I love that for it π
π SEE ALSO π
bitmap(3)β the other bitmap bestiebitstring(3)β the bitstring bestie, go say hi π¦
β οΈ CAVEATS β οΈ
The number of valid bits in a given array is assumed to be multiple of CHAR_BIT β that's the number of bits for smallest object that is not a bit-field. So yeah, keep that in mind before you start vibing with arbitrary bit counts ππ
xoxo, this page is from Debian π dated December 4, 2012 β¨ β SETBIT(9) out, bestie! ππ¦
π¦ where this page comes from
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c) 2010 The NetBSD Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms