STDC_HAS_SINGLE_BIT(3)

πŸ“¦ version 15.1, in freebsd 15.1

🌸 STDC_HAS_SINGLE_BIT(3) 🌸

okay bestie, we're in the Library Functions Manual today and this one is coming to you straight from libc (-lc) πŸ’… buckle up, it's a short one but it's iconic.


✨ NAME ✨

stdc_has_single_bit β€” check for single bit set πŸŽ€

literally does what it says on the tin, she looks at your number and goes "is there exactly ONE bit lit up in here?"


πŸ’– SYNOPSIS πŸ’–

Standard C Library (libc, -lc) #include <stdbit.h>

bool
stdc_has_single_bit_uc(unsigned char value);

bool
stdc_has_single_bit_us(unsigned short value);

bool
stdc_has_single_bit_ui(unsigned int value);

bool
stdc_has_single_bit_ul(unsigned long value);

bool
stdc_has_single_bit_ull(unsigned long long value);

bool
stdc_has_single_bit(value);

like, all of these exist, pick your fighter 🫢 and yes the last one has no type in the name β€” that's on purpose, she's the main character macro, iykyk.


πŸ¦‹ DESCRIPTION πŸ¦‹

so. the stdc_has_single_bit_type() family of functions checks if there is exactly one bit set in 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. no cap, that's the whole bit (pun intended πŸ’€).

and the stdc_has_single_bit(value) type-generic macro? she's the queen of delegation πŸ‘‘ she picks the appropriate stdc_has_single_bit_type() function based on the type of value. you don't gotta do anything, she just knows.

the functions in this family behave similarly to the powerof2(value) macro of <sys/param.h>, but β€” and this is the tea πŸ“ β€” they differ when value is zero: while powerof2() considers zero to be a power of two, stdc_has_single_bit() does not. zero is not invited to that party, periodt.

not me warning you about this: if you're porting code from powerof2() over to this, the zero case WILL trip you up fr fr πŸ™ˆ

🌈 RETURN VALUES 🌈

Returns true if exactly one bit is set in value, otherwise returns false. I.e. the function determines if value is a power of two. 🎯

so: yes βœ… or no ❌. no in-between, no "maybe", she's not that kind of function.


πŸ”₯ SEE ALSO πŸ”₯

go read those next bestie, the whole stdbit cinematic universe is right there 🎬


⭐ STANDARDS ⭐

The stdc_has_single_bit_type() family of functions and the stdc_has_single_bit() type-generic macro conform to .

^(yep, that reference is literally blank in the original and I'm leaving it exactly as-is β€” no inventing, that's the rule πŸ’…)


🧚 HISTORY 🧚

The stdc_has_single_bit_type() family of functions and the stdc_has_single_bit() type-generic macro were added in FreeBSD 15.1. ✨ fresh off the press, relatively speaking πŸŽ€


πŸ’œ AUTHOR πŸ’œ

Robert Clausecker <fuz@FreeBSD.org> β€” thank you king, this API ate and left no crumbs πŸ‘


and that's the whole page bestie!! πŸ’– this beauty ships out under Debian, dated November 9, 2025, and it's the STDC_HAS_SINGLE_BIT(3) page in all her glory 🌸 go check your bits, ily, bye 🫢

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