STDC_LEADING_ZEROS(3)

πŸ“¦ version 15.1, in freebsd 15.1

πŸ’… STDC_LEADING_ZEROS(3) β€” the library-functions-manual one ✨

okay so bestie, we're in section 3 of the Library Functions Manual, and today's main character is a whole little family of functions that count zeros. yes, zeros. leading ones. it's giving "why would anyone need this" until you need it, and then you REALLY need it. 🫢


✨ NAME ✨

stdc_leading_zeros β€” find the number of leading zeros in an integer πŸ’–


πŸŽ€ SYNOPSIS πŸŽ€

Standard C Library (libc, -lc)

#include <stdbit.h>
unsigned int
stdc_leading_zeros_uc(unsigned char value);
unsigned int
stdc_leading_zeros_us(unsigned short value);
unsigned int
stdc_leading_zeros_ui(unsigned int value);
unsigned int
stdc_leading_zeros_ul(unsigned long value);
unsigned int
stdc_leading_zeros_ull(unsigned long long value);
unsigned int
stdc_leading_zeros(value);

🌸 DESCRIPTION 🌸

so the stdc_leading_zeros_type() family of functions returns the number of leading zeros in value β€” like, how many sad empty bits sit at the front before the first 1 shows up. πŸ‘‘

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 suffixes are literally just the type, spelled short. no cap. πŸ¦‹

and then there's stdc_leading_zeros(value), the type-generic macro β€” she looks at the type of value and picks the appropriate stdc_leading_zeros_type() function for you. main character energy: you don't choose the suffix, the macro chooses the suffix for you. ✨


πŸ’€ RETURN VALUES πŸ’€

returns the number of leading zeros in value. πŸ’…

and if value is all zeros? then you get the total number of bits in the type of value returned to you. all of them. every single bit is a leading zero at that point, which is honestly so real of it. 😭


πŸ”₯ SEE ALSO πŸ”₯

(the whole bit-nerd friend group, go say hi πŸ’œ)


🌈 STANDARDS 🌈

the stdc_leading_zeros_type() family of functions and the stdc_leading_zeros() type-generic macro conform to … . β€” okay so the original page literally just says "conform to ." with the citation missing, iykyk, I'm not gonna invent a standard for you bestie, I'm just telling you exactly what it says. 🫠


⭐ HISTORY ⭐

the stdc_leading_zeros_type() family of functions and the stdc_leading_zeros() type-generic macro were added in FreeBSD 15.1. πŸŽ€


πŸ‘‘ AUTHOR πŸ‘‘

Robert Clausecker <fuz@FreeBSD.org> β€” icon, legend, the moment. 🧚


and that's the page, bestie!! this one shipped on the Debian side of things, dated November 9, 2025 β€” the STDC_LEADING_ZEROS(3) page, countin' zeros so you don't have to. mwah πŸ’‹βœ¨

πŸ“¦ 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