FFS(3)
๐ FFS(3) โ find first or last bit set in a bit string
okay bestie, welcome to the Library Functions Manual corner of the internet, where we learn how to find your first and/or last bit that is set. yes. we're doing bit math. and honestly? it's kinda iconic. ๐
โจ NAME โจ
ffs, ffsl, ffsll, fls, flsl, flsll โ find first or last bit set in a bit string ๐ฆ
๐ LIBRARY ๐
Standard C Library โ that's libc, and you link it with -lc. slay.
๐ธ SYNOPSIS ๐ธ
#include <strings.h>
int
ffs(int value);
int
ffsl(long value);
int
ffsll(long long value);
int
fls(int value);
int
flsl(long value);
int
flsll(long long value);
๐ DESCRIPTION ๐
okay so here's the whole vibe, and it's genuinely not that deep:
ffs(),ffsl(),ffsll()โ these find the first (aka the least significant) bit that's set invalue, and they hand you back the index of that bit. ๐ฅfls(),flsl(),flsll()โ same energy but from the other end: they find the last (aka the most significant) bit that's set invalue, and return its index. ๐
and the counting system? bits are numbered starting at 1, and 1 is the least significant bit. no zero-indexing here, we're quirky like that.
โ ๏ธ one thing fr fr: if any of these functions return zero, it means your argument was zero. like, zero bits set. empty. no bits. that's the whole tell. ๐
๐ SEE ALSO ๐
๐ STANDARDS ๐
ffs()conforms toIEEE Std 1003.1-2008 (โPOSIX.1โ). periodt. โffsl()andffsll()conform to . โ yes, that's literally how it's written, the standard reference is blank in the original, so please don't @ me, I'm just the messenger ๐ซถ
๐ง HISTORY ๐ง
ffs()appeared in4.3BSD. and get this โ its prototype lived its best life in<string.h>before it was moved to<strings.h>forIEEE Std 1003.1-2001 (โPOSIX.1โ)compliance. glow-up tbh โจffsl(),fls(), andflsl()appeared inFreeBSD 5.3. ๐ffsll()andflsll()appeared inFreeBSD 7.1. later bloomers, still icons ๐
okay that's the whole page bestie, go set some bits ๐ โ from the Debian crew, page dated October 25, 2025, filed under FFS(3), mwah ๐
๐ฆ where this page comes from
- freebsd 15.1: base 15.1
- Copyright (c) 1990, 1991, 1993 The Regents of the University of California. All rights reserved
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms