1.\" 2.\" Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org> 3.\" 4.\" SPDX-License-Identifier: BSD-2-Clause 5.\" 6.Dd November 9, 2025 7.Dt STDC_FIRST_TRAILING_ONE 3 8.Os 9.Sh NAME 10.Nm stdc_first_trailing_one 11.Nd find the first trailing one in an integer 12.Sh SYNOPSIS 13.Lb libc 14.In stdbit.h 15.Ft unsigned int 16.Fn stdc_first_trailing_one_uc "unsigned char value" 17.Ft unsigned int 18.Fn stdc_first_trailing_one_us "unsigned short value" 19.Ft unsigned int 20.Fn stdc_first_trailing_one_ui "unsigned int value" 21.Ft unsigned int 22.Fn stdc_first_trailing_one_ul "unsigned long value" 23.Ft unsigned int 24.Fn stdc_first_trailing_one_ull "unsigned long long value" 25.Ft unsigned int 26.Fn stdc_first_trailing_one "value" 27.Sh DESCRIPTION 28The 29.Nm stdc_first_trailing_one_ Ns Em type Ns () 30family of functions returns the index of the least significant set bit in 31.Fa value , 32where 33.Fa value 34is of type 35.Va unsigned char , 36.Va unsigned short , 37.Va unsigned int , 38.Va unsigned long , 39or 40.Va unsigned long long 41for 42.Em type 43being 44.Sy uc , 45.Sy us , 46.Sy ui , 47.Sy ul , 48or 49.Sy ull 50respectively. 51The 52.Fn stdc_first_trailing_one "value" 53type-generic macro picks the appropriate 54.Nm stdc_first_trailing_one_ Ns Em type Ns () 55function based on the type of 56.Fa value . 57.Pp 58Functions 59.Fn stdc_first_trailing_one_ui , 60.Fn stdc_first_trailing_one_ul , 61and 62.Fn stdc_first_trailing_one_ull 63are identical to 64.Bx 4.3 65functions 66.Xr ffs 3 , 67.Xr ffsl 3 , 68and 69.Xr ffsll 3 70respectively, except for operating on unsigned instead of signed values. 71.Sh RETURN VALUES 72Returns the index of the least significant set bit in 73.Fa value . 74The bits are numbered such that the least significant bit has number\~1, 75and the most significant bit has number 76.Ms w 77where 78.Ms w 79is the number of bits in the type of 80.Fa value . 81If no bits are set in 82.Fa value 83(i.\^e.\& 84.Fa value 85is zero), one is returned. 86.Sh SEE ALSO 87.Xr bit_ffs 3 , 88.Xr ffs 3 , 89.Xr ffsl 3 , 90.Xr ffsll 3 , 91.Xr stdbit 3 , 92.Xr stdc_trailing_zeros 3 , 93.Xr stdc_first_trailing_zero 3 , 94.Xr stdc_first_leading_one 3 95.Sh STANDARDS 96The 97.Nm stdc_first_trailing_one_ Ns Em type Ns () 98family of functions and the 99.Fn stdc_first_trailing_one 100type-generic macro conform to 101.St -isoC-2023 . 102.Sh HISTORY 103The 104.Nm stdc_first_trailing_one_ Ns Em type Ns () 105family of functions and the 106.Fn stdc_first_trailing_one 107type-generic macro were added in 108.Fx 15.1. 109.Sh AUTHOR 110.An Robert Clausecker Aq Mt fuz@FreeBSD.org 111