STDBIT(3)

πŸ“¦ version 15.1, in freebsd 15.1

🌸 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:

⭐ 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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms