SETBIT(9)

πŸ“¦ version 11.0, in nixpkgs unstable

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 πŸ’…

⚠️ 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