FFS32(3)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸ’– FFS32(3): find first or last bit set πŸ’–

okay bestie, welcome to the Library Functions Manual page for FFS32(3) β€” the bit-hunting crew. It’s giving low-level but make it cute. No cap, every detail is here. ✨

🌸 NAME 🌸

  • ffs32, ffs64, fls32, fls64 β€” find first or last bit set

πŸ¦‹ SYNOPSIS πŸ¦‹

#include <sys/bitops.h>

int
ffs32(uint32_t n);

int
ffs64(uint64_t n);

int
fls32(uint32_t n);

int
fls64(uint64_t n);

πŸŽ€ DESCRIPTION πŸŽ€

okay so ffs32() and ffs64() are the find-first besties: they find the first bit set in n and return the index of that bit. Conversely, fls32() and fls64() are the find-last girlies: they find the last bit set in n, returning the index of the bit. Literally their whole main character job. πŸ’… Periodt.

The search always starts from bit 1 (the least significant bit). If the argument n is zero, each function returns zero. Vibe check passed: zero in, zero out β€” that’s the rule on the page. 🫢

🧚 IMPLEMENTATION NOTES 🧚

Real talk, lowkey: the described functions are implemented as static inline functions in the <sys/bitops.h> header. The standard C library includes a more portable ffs(3) for user applications. So if you’re out here in userland, iykyk fr fr. πŸ’œ

🌈 EXAMPLES 🌈

In the following example f = 3 and l = 7:

uint32_t n = 0x44;      /* 01000100 */
int f, l;

f = ffs32(n);
l = fls32(n);

not me loving a tiny example that ate. ✨ Obsessed.

πŸ”₯ SEE ALSO πŸ”₯

πŸ‘‘ HISTORY πŸ‘‘

These functions first appeared in NetBSD 5.0. iconic behavior, honestly. ngl, we love a debut. πŸ’–


mwah πŸ’‹ β€” this page comes from Debian, dated April 8, 2011, with manual title FFS32(3). Bye bestie, go find those bits! 🫢🌷

πŸ“¦ where this page comes from