STDBIT(3)
πΈ NAME πΈ
stdbit(3) β bit and byte utilities. This is the Library Functions Manual entry for the <stdbit.h> bit/byte utility crew. π
β¨ SYNOPSIS β¨
Okay bestie, the standard C library is libc β link it with -lc β and the header is <stdbit.h>. Hereβs the synopsis in all its glory:
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(value)
stdc_bit_floor(value);
typeof(value)
stdc_bit_ceil(value);
Thatβs the whole function lineup, no cap. π
π DESCRIPTION π
First up: endianness. 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. Thatβs the whole endianness tea. π
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. So yes, thereβs a flavor for every unsigned width, and the suffixes are literally right there. π
Additionally, for each func, a type-generic macro stdc_func(value) is provided. It picks the appropriate function stdc_func_type(value) based on the type of value. Itβs giving βthe macro knows which one you meantβ energy. π¦
π SEE ALSO π
Go read these too, iykyk:
arch(7)bitstring(3)ffs(3)fls(3)stdc_count_leading_zeros(3)stdc_count_leading_ones(3)stdc_count_trailing_zeros(3)stdc_count_trailing_ones(3)stdc_first_leading_zero(3)stdc_first_leading_one(3)stdc_first_trailing_zero(3)stdc_first_trailing_one(3)stdc_count_zeros(3)stdc_count_ones(3)stdc_has_single_bit(3)stdc_bit_width(3)stdc_bit_floor(3)stdc_bit_ceil(3)
β STANDARDS β
The macros and functions of the <stdbit.h> header conform to . Yes, bestie, the source sentence really does end there β no standard name is listed. π
π¦ HISTORY π¦
The <stdbit.h> header and the macros and functions defined therein were added in FreeBSD 15.1. Periodt. π₯
π AUTHOR π
Robert Clausecker <fuz@FreeBSD.org>. Show some love. π«Ά
π Cute sign-off: this page is from Debian, dated November 9, 2025, and the manual is STDBIT(3). Bye bestie, go count some bits! π
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π the page's license: BSD-2-Clause
- Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms