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.\" 4. 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.\" @(#)ffs.3 8.2 (Berkeley) 4/19/94 31.\" $FreeBSD: src/lib/libc/string/ffs.3,v 1.13 2009/01/13 13:19:42 kib Exp $ 32.\" $DragonFly: src/lib/libc/string/ffs.3,v 1.2 2003/06/17 04:26:46 dillon Exp $ 33.\" 34.Dd October 26, 2008 35.Dt FFS 3 36.Os 37.Sh NAME 38.Nm ffs , 39.Nm ffsl , 40.Nm ffsll , 41.Nm fls , 42.Nm flsl , 43.Nm flsll 44.Nd find first or last bit set in a bit string 45.Sh LIBRARY 46.Lb libc 47.Sh SYNOPSIS 48.In strings.h 49.Ft int 50.Fn ffs "int value" 51.Ft int 52.Fn ffsl "long value" 53.Ft int 54.Ft int 55.Fn ffsll "long long value" 56.Fn fls "int value" 57.Ft int 58.Fn flsl "long value" 59.Ft int 60.Fn flsll "long long value" 61.Sh DESCRIPTION 62The 63.Fn ffs , 64.Fn ffsl 65and 66.Fn ffsll 67functions find the first bit set 68(beginning with the least significant bit) 69in 70.Fa value 71and return the index of that bit. 72.Pp 73The 74.Fn fls , 75.Fn flsl 76and 77.Fn flsll 78functions find the last bit set in 79.Fa value 80and return the index of that bit. 81.Pp 82Bits are numbered starting at 1 (the least significant bit). 83A return value of zero from any of these functions means that the 84argument was zero. 85.Sh SEE ALSO 86.Xr bitstring 3 87.Sh HISTORY 88The 89.Fn ffs 90function appeared in 91.Bx 4.3 . 92Its prototype existed previously in 93.In string.h 94before it was moved to 95.In strings.h 96for 97.St -p1003.1-2001 98compliance. 99.Pp 100The 101.Fn ffsl , 102.Fn fls 103and 104.Fn flsl 105functions appeared in 106.Fx 5.3 . 107The 108.Fn ffsll 109and 110.Fn flsll 111functions appeared in 112.Fx 7.1 . 113