find_nth_bit(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… find_nth_bit(9) β€” Kernel API Manual, bestie edition πŸŽ€

okay so this is a page from the Kernel API Manual and honestly? it's a little cutie. like, it's short, it's sweet, it finds the N'th set bit. we love a focused icon.


✨ NAME ✨

find_nth_bit β€” find the N'th set bit in a memory region πŸ’–


πŸ¦‹ SYNOPSIS πŸ¦‹

unsigned long find_nth_bit (const unsigned long *addr , unsigned long
size , unsigned long n );

like, yes, the line break in the middle is real, that's just how it's printed, don't come for her πŸ’…


🌸 ARGUMENTS 🌸

  • addr β€” The address to start the search at πŸ” this is where you begin hunting
  • size β€” The maximum number of bits to search πŸ™ˆ know your limits bestie
  • n β€” The number of set bit, which position is needed, counting from 0 ⭐ like, zero-indexed, periodt

πŸ‘‘ DESCRIPTION πŸ‘‘

okay so the following is semantically equivalent, meaning these two are giving the exact same energy:

idx = find_nth_bit(addr, size, 0);
idx = find_first_bit(addr, size);

not me pointing out that asking for the 0th set bit is literally just find_first_bit. iconic behavior. 🀝

So what does she actually do? Returns the bit number of the N'th set bit. that's it, that's the whole vibe.

And if no such bit exists? she returns >= size. so like, check your result against size, because anything at or past it means "nope, didn't find it" 😭 no cap.


🌈 SEE ALSO 🌈

Kernel file ./include/linux/find.h β€” and honestly the friend group here is HUGE, so buckle up bestie, we're listing everybody 🫢

all twenty-two of them. every single one. main character energy across the whole entire header file fr fr πŸ”₯


quick vibe check: if you only remember one thing, remember that "not found" looks like >= size, not a magic negative number. don't get caught out there. πŸ’€

kisses and bit-twiddling, bestie πŸ’œ this page lives in ./include/linux and the version/date stamp says October 2026 β€” so yes, she's from the future and she's still slaying 🧚✨

πŸ“¦ where this page comes from