find_nth_bit(9)
π 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 huntingsizeβ The maximum number of bits to search π know your limits bestienβ The number of set bit, which position is needed, counting from0β 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 π«Ά
find_next_bit(9)find_next_and_bit(9)find_next_andnot_bit(9)find_next_or_bit(9)find_next_zero_bit(9)find_first_bit(9)find_nth_and_bit(9)find_nth_and_andnot_bit(9)find_first_and_bit(9)find_first_andnot_bit(9)find_first_and_and_bit(9)find_first_zero_bit(9)find_last_bit(9)find_next_and_bit_wrap(9)find_next_bit_wrap(9)find_next_clump8(9)for_each_set_bitrange(9)for_each_set_bitrange_from(9)for_each_clear_bitrange(9)for_each_clear_bitrange_from(9)for_each_set_bit_wrap(9)for_each_set_clump8(9)
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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms