---
name: "stdbit"
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/stdbit"
---

# stdbit(3)

bit and byte utilities

## NAME

**stdbit** – bit and byte utilities

## SYNOPSIS

Standard C Library (libc, -lc)

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

**#define \_\_STDC\_ENDIAN\_LITTLE\_\_**

**#define \_\_STDC\_ENDIAN\_BIG\_\_**

**#define \_\_STDC\_ENDIAN\_NATIVE\_\_**

*unsigned* *int*\

**stdc\_count\_leading\_zeros**(*value*);

*unsigned* *int*\

**stdc\_count\_leading\_ones**(*value*);

*unsigned* *int*\

**stdc\_count\_trailing\_zeros**(*value*);

*unsigned* *int*\

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

*unsigned* *int*\

**stdc\_first\_leading\_zero**(*value*);

*unsigned* *int*\

**stdc\_first\_leading\_one**(*value*);

*unsigned* *int*\

**stdc\_first\_trailing\_zero**(*value*);

*unsigned* *int*\

**stdc\_first\_trailing\_one**(*value*);

*unsigned* *int*\

**stdc\_count\_zeros**(*value*);

*unsigned* *int*\

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

*bool*\

**stdc\_has\_single\_bit**(*value*);

*unsigned* *int*\

**stdc\_bit\_width**(*value*);

*typeof* *Ns* *Pq* *Em* *value*\

**stdc\_bit\_floor**(*value*);

*typeof* *Ns* *Pq* *Em* *value*\

**stdc\_bit\_ceil**(*value*);

## DESCRIPTION

The \_\_STDC\_ENDIAN\_NATIVE\_\_ macro describes the byte order or endianness of the machine for which the program is built. If the machine has big-endian byte order, this macro is equal to \_\_STDC\_ENDIAN\_BIG\_\_. If the machine has little-endian byte order, this macro is equal to \_\_STDC\_ENDIAN\_LITTLE\_\_. Otherwise, the macro has a value that is equal to neither.

The bit and byte utility functions analyze the bits within a datum. Each function *func* is provided in five variants **stdc\_***func**\_**type*(*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. Additionally, for each *func*, a type-generic macro **stdc\_***func*(*value*) that picks the appropriate function **stdc\_***func**\_**type*(*value*) based on the type of *value* is provided.

## SEE ALSO

[bitstring(3)](/bitstring/3.md), [ffs(3)](/ffs/3.md), [fls(3)](/fls/3.md), [stdc\_bit\_ceil(3)](/stdc_bit_ceil/3.md), [stdc\_bit\_floor(3)](/stdc_bit_floor/3.md), [stdc\_bit\_width(3)](/stdc_bit_width/3.md), stdc\_count\_leading\_ones(3), stdc\_count\_leading\_zeros(3), [stdc\_count\_ones(3)](/stdc_count_ones/3.md), stdc\_count\_trailing\_ones(3), stdc\_count\_trailing\_zeros(3), [stdc\_count\_zeros(3)](/stdc_count_zeros/3.md), [stdc\_first\_leading\_one(3)](/stdc_first_leading_one/3.md), [stdc\_first\_leading\_zero(3)](/stdc_first_leading_zero/3.md), [stdc\_first\_trailing\_one(3)](/stdc_first_trailing_one/3.md), [stdc\_first\_trailing\_zero(3)](/stdc_first_trailing_zero/3.md), [stdc\_has\_single\_bit(3)](/stdc_has_single_bit/3.md), [arch(7)](/arch/7.md)

## STANDARDS

The macros and functions of the ⟨stdbit.h⟩ header conform to ISO/IEC 9899:2024 (“ISO C23”).

## HISTORY

The ⟨stdbit.h⟩ header and the macros and functions defined therein where added in FreeBSD 15.1.

## AUTHORS

Robert Clausecker ⟨*fuz@FreeBSD.org*⟩
