STDC_HAS_SINGLE_BIT(3)

NAME
stdc_has_single_bit - check for single bit set

SYNOPSIS
libc
#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
stdbit(3), stdc_count_ones(3)

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

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.

AUTHOR
Robert Clausecker <fuz@FreeBSD.org>