STDC_LEADING_ONES(3) FreeBSD Library Functions Manual STDC_LEADING_ONES(3)
NAME
stdc_leading_ones - find the number of leading ones in an integer
SYNOPSIS
/* -lc */
#include <stdbit.h>
unsigned int
stdc_leading_ones_uc(unsigned char value);
unsigned int
stdc_leading_ones_us(unsigned short value);
unsigned int
stdc_leading_ones_ui(unsigned int value);
unsigned int
stdc_leading_ones_ul(unsigned long value);
unsigned int
stdc_leading_ones_ull(unsigned long long value);
unsigned int
stdc_leading_ones(value);
DESCRIPTION
The stdc_leading_ones_type() family of functions returns the number of
leading ones in value, where value is of type unsigned char, unsigned
short, unsigned int, unsigned long, or unsigned long long for type being
uc, us, ui, ul, or ull respectively. The stdc_leading_ones(value) type-
generic macro picks the appropriate stdc_leading_ones_type() function
based on the type of value.
RETURN VALUES
Returns the number of leading ones in value. If value is all ones, the
total number of bits in the type of value is returned.
SEE ALSO
stdbit(3), stdc_leading_zeros(3), stdc_trailing_ones(3),
stdc_first_leading_zero(3)
STANDARDS
The stdc_leading_ones_type() family of functions and the
stdc_leading_ones() type-generic macro conform to ISO/IEC 9899:2024
("ISO C23").
HISTORY
The stdc_leading_ones_type() family of functions and the
stdc_leading_ones() type-generic macro were added in FreeBSD 15.1.
AUTHOR
Robert Clausecker <fuz@FreeBSD.org>
FreeBSD 15.1-STABLE-HBSD November 9, 2025 STDC_LEADING_ONES(3)