1.\" Copyright (c) 1990, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" Chris Torek. 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. Neither the name of the University nor the names of its contributors 15.\" may be used to endorse or promote products derived from this software 16.\" without specific prior written permission. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28.\" SUCH DAMAGE. 29.\" 30.Dd October 25, 2025 31.Dt FFS 3 32.Os 33.Sh NAME 34.Nm ffs , 35.Nm ffsl , 36.Nm ffsll , 37.Nm fls , 38.Nm flsl , 39.Nm flsll 40.Nd find first or last bit set in a bit string 41.Sh LIBRARY 42.Lb libc 43.Sh SYNOPSIS 44.In strings.h 45.Ft int 46.Fn ffs "int value" 47.Ft int 48.Fn ffsl "long value" 49.Ft int 50.Fn ffsll "long long value" 51.Ft int 52.Fn fls "int value" 53.Ft int 54.Fn flsl "long value" 55.Ft int 56.Fn flsll "long long value" 57.Sh DESCRIPTION 58The 59.Fn ffs , 60.Fn ffsl 61and 62.Fn ffsll 63functions find the first (least significant) bit set 64in 65.Fa value 66and return the index of that bit. 67.Pp 68The 69.Fn fls , 70.Fn flsl 71and 72.Fn flsll 73functions find the last (most significant) bit set in 74.Fa value 75and return the index of that bit. 76.Pp 77Bits are numbered starting at 1, the least significant bit. 78A return value of zero from any of these functions means that the 79argument was zero. 80.Sh SEE ALSO 81.Xr bitstring 3 , 82.Xr bitset 9 83.Sh STANDARDS 84The 85.Fn ffs 86function conforms to 87.St -p1003.1-2008 . 88The 89.Fn ffsl 90and 91.Fn ffsll 92functions conform to 93.St -p1003.1-2024 . 94.Sh HISTORY 95The 96.Fn ffs 97function appeared in 98.Bx 4.3 . 99Its prototype existed previously in 100.In string.h 101before it was moved to 102.In strings.h 103for 104.St -p1003.1-2001 105compliance. 106.Pp 107The 108.Fn ffsl , 109.Fn fls 110and 111.Fn flsl 112functions appeared in 113.Fx 5.3 . 114The 115.Fn ffsll 116and 117.Fn flsll 118functions appeared in 119.Fx 7.1 . 120