STDC_FIRST_LEADING_ZERO(3)
π STDC_FIRST_LEADING_ZERO(3) β find the first leading zero in an integer
okay bestie, so this one lives in the Standard C Library β that's libc, link it with -lc β and it's all about finding that first lil zero hiding at the front of your integer. let's get into it π
β¨ SYNOPSIS β¨
first things first, you gotta invite the header:
#include <stdbit.h>
and here's the whole squad, all of them returning unsigned int:
unsigned int
stdc_first_leading_zero_uc(unsigned char value);
unsigned int
stdc_first_leading_zero_us(unsigned short value);
unsigned int
stdc_first_leading_zero_ui(unsigned int value);
unsigned int
stdc_first_leading_zero_ul(unsigned long value);
unsigned int
stdc_first_leading_zero_ull(unsigned long long value);
unsigned int
stdc_first_leading_zero(value);
π¦ DESCRIPTION π¦
so the stdc_first_leading_zero_type() family (yes, _type is the placeholder, keep up π) hands you back the index of the most significant clear bit in value. and value can be any of these:
unsigned charβ that'sucunsigned shortβ that'susunsigned intβ that'suiunsigned longβ that'sulunsigned long longβ that'sull
match them up respectively, iykyk π«
and then there's stdc_first_leading_zero(value) β the type-generic macro β which is the main character here fr. it looks at whatever type value actually is and picks the right stdc_first_leading_zero_type() function for you. no cap, it just knows. π
π₯ RETURN VALUES π₯
it returns the index of the most significant clear bit in value. and the numbering? listen closely bestie:
- the most significant bit is number 1
- the least significant bit is number w, where w is the number of bits in the type of
value
and here's the little plot twist π β if there are no clear bits in value at all (like, value is the bitwise complement of zero), it returns zero. that's your "nothing to see here" signal. π
π SEE ALSO π
go read these next, they're literally the friend group:
stdbit(3)stdc_leading_ones(3)stdc_first_leading_ones(3)stdc_first_trailing_zero(3)
β STANDARDS β
the stdc_first_leading_zero_type() family of functions and the stdc_first_leading_zero() type-generic macro conform to .
ok so the standard name is literally blank in the source page π« not me pointing it out, but yeah, that's the whole line. keeping it 100% as-is.
π§ HISTORY π§
the stdc_first_leading_zero_type() family of functions and the stdc_first_leading_zero() type-generic macro were added in FreeBSD 15.1. fresh out the oven, periodt. β¨
π AUTHOR π
Robert Clausecker <fuz@FreeBSD.org> β ty for your service bestie π«Ά
so yeah, that's the page!! this one's from Debian, dated November 9, 2025 β go find your leading zeros, slay, and remember: bit 1 is the most significant one, don't embarrass yourself π πΈ
π¦ 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