STDC_LEADING_ONES(3)
π STDC_LEADING_ONES(3) π
Library Functions Manual? More like library functions bestie manual π okay so welcome to the group chat, we're learning how to count leading ones and it's lowkey iconic.
πΈ NAME πΈ
stdc_leading_ones β find the number of leading ones in an integer π
β¨ SYNOPSIS β¨
Link the Standard C Library: Standard C Library (libc, -lc). Header first, bestie: #include <stdbit.h>.
unsigned int
stdc_leading_ones_uc(unsigned char value);
unsigned int
stdc_leading_ones_us(unsigned short value);
unsigned int
stdc_leading_ones_ui(unsigned int value);
unsigned int
stdc_leading_ones_ul(unsigned long value);
unsigned int
stdc_leading_ones_ull(unsigned long long value);
unsigned int
stdc_leading_ones(value);
π¦ DESCRIPTION π¦
Okay so the stdc_leading_ones_type() family of functions returns the number of leading ones in value β¨. Here value is of type unsigned char, unsigned short, unsigned int, unsigned long, or unsigned long long, and type is uc, us, ui, ul, or ull respectively π
.
The stdc_leading_ones(value) type-generic macro is the main character here: it picks the appropriate stdc_leading_ones_type() function based on the type of value π«Ά. No cap, it just knows.
π RETURN VALUES π
Returns the number of leading ones in value. If value is all ones, the total number of bits in the type of value is returned π₯. So bestie, if it's literally all 1s, you get the whole bit-width back.
π SEE ALSO π
Go sip on those too, they're all in the same friend group π
β STANDARDS β
The stdc_leading_ones_type() family of functions and the stdc_leading_ones() type-generic macro conform to . π (That's what the page says, don't come for me.)
π HISTORY π
The stdc_leading_ones_type() family of functions and the stdc_leading_ones() type-generic macro were added in FreeBSD 15.1 β¨ periodt.
π AUTHOR π
Robert Clausecker <fuz@FreeBSD.org> π«Ά
π Source/version: Debian β date: November 9, 2025 π
π¦ 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