NAME
stdc_has_single_bit – check for single bit set
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);
DESCRIPTION
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. The stdc_has_single_bit(value) type-generic macro picks the appropriate stdc_has_single_bit_type() function based on the type of value.
The functions in this family behave similarly to the powerof2(value) macro of ⟨sys/param.h⟩, but differ when value is zero: while powerof2() considers zero to be a power of two, stdc_has_single_bit() does not.
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.
SEE ALSO
STANDARDS
The stdc_has_single_bit_type() family of functions and the stdc_has_single_bit() type-generic macro conform to ISO/IEC 9899:2024 (“ISO C23”).
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.
AUTHORS
Robert Clausecker ⟨[email protected]⟩