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), ffs(3), fls(3), stdc_bit_ceil(3), stdc_bit_floor(3), stdc_bit_width(3), stdc_count_leading_ones(3), stdc_count_leading_zeros(3), stdc_count_ones(3), stdc_count_trailing_ones(3), stdc_count_trailing_zeros(3), stdc_count_zeros(3), stdc_first_leading_one(3), stdc_first_leading_zero(3), stdc_first_trailing_one(3), stdc_first_trailing_zero(3), stdc_has_single_bit(3), arch(7)
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 ⟨[email protected]⟩