---
name: "stdc_trailing_ones"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/stdc_trailing_ones"
---

# stdc\_trailing\_ones(3)

find the number of trailing ones in an integer

## NAME

**stdc\_trailing\_ones** – find the number of trailing ones in an integer

## SYNOPSIS

Standard C Library (libc, -lc)

**#include \<stdbit.h\>**

*unsigned* *int*\

**stdc\_trailing\_ones\_uc**(*unsigned char value*);

*unsigned* *int*\

**stdc\_trailing\_ones\_us**(*unsigned short value*);

*unsigned* *int*\

**stdc\_trailing\_ones\_ui**(*unsigned int value*);

*unsigned* *int*\

**stdc\_trailing\_ones\_ul**(*unsigned long value*);

*unsigned* *int*\

**stdc\_trailing\_ones\_ull**(*unsigned long long value*);

*unsigned* *int*\

**stdc\_trailing\_ones**(*value*);

## DESCRIPTION

The **stdc\_trailing\_ones\_***type*() family of functions returns the number of trailing 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\_trailing\_ones**(*value*) type-generic macro picks the appropriate **stdc\_trailing\_ones\_***type*() function based on the type of *value*.

## RETURN VALUES

Returns the number of trailing ones in *value*. If *value* is all ones, the total number of bits in the type of *value* is returned.

## SEE ALSO

[stdbit(3)](/stdbit/3.md), [stdc\_first\_trailing\_zero(3)](/stdc_first_trailing_zero/3.md), [stdc\_leading\_ones(3)](/stdc_leading_ones/3.md), [stdc\_trailing\_zeros(3)](/stdc_trailing_zeros/3.md)

## STANDARDS

The **stdc\_trailing\_ones\_***type*() family of functions and the **stdc\_trailing\_ones**() type-generic macro conform to ISO/IEC 9899:2024 (“ISO C23”).

## HISTORY

The **stdc\_trailing\_ones\_***type*() family of functions and the **stdc\_trailing\_ones**() type-generic macro were added in FreeBSD 15.1.

## AUTHORS

Robert Clausecker ⟨*fuz@FreeBSD.org*⟩
