xref: /freebsd/lib/libc/stdbit/stdc_has_single_bit.3 (revision d790b16bbf0c3055ef00200d01659dfb3c0e5e5e)
1.\"
2.\" Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
3.\"
4.\" SPDX-License-Identifier: BSD-2-Clause
5.\"
6.Dd November 9, 2025
7.Dt STDC_HAS_SINGLE_BIT 3
8.Os
9.Sh NAME
10.Nm stdc_has_single_bit
11.Nd check for single bit set
12.Sh SYNOPSIS
13.Lb libc
14.In stdbit.h
15.Ft bool
16.Fn stdc_has_single_bit_uc "unsigned char value"
17.Ft bool
18.Fn stdc_has_single_bit_us "unsigned short value"
19.Ft bool
20.Fn stdc_has_single_bit_ui "unsigned int value"
21.Ft bool
22.Fn stdc_has_single_bit_ul "unsigned long value"
23.Ft bool
24.Fn stdc_has_single_bit_ull "unsigned long long value"
25.Ft bool
26.Fn stdc_has_single_bit "value"
27.Sh DESCRIPTION
28The
29.Nm stdc_has_single_bit_ Ns Em type Ns ()
30family of functions checks if there is exactly one bit
31set in
32.Fa value ,
33where
34.Fa value
35is of type
36.Va unsigned char ,
37.Va unsigned short ,
38.Va unsigned int ,
39.Va unsigned long ,
40or
41.Va unsigned long long
42for
43.Em type
44being
45.Sy uc ,
46.Sy us ,
47.Sy ui ,
48.Sy ul ,
49or
50.Sy ull
51respectively.
52The
53.Fn stdc_has_single_bit "value"
54type-generic macro picks the appropriate
55.Nm stdc_has_single_bit_ Ns Em type Ns ()
56function based on the type of
57.Fa value .
58.Pp
59The functions in this family behave similarly to the
60.Fn powerof2 "value"
61macro of
62.In sys/param.h ,
63but differ when
64.Fa value
65is zero: while
66.Fn powerof2
67considers zero to be a power of two,
68.Fn stdc_has_single_bit
69does not.
70.Sh RETURN VALUES
71Returns
72.Sy true
73if exactly one bit is set in
74.Fa value ,
75otherwise returns
76.Sy false .
77I.\^e. the function determines if
78.Fa value
79is a power of two.
80.Sh SEE ALSO
81.Xr stdbit 3 ,
82.Xr stdc_count_ones 3
83.Sh STANDARDS
84The
85.Nm stdc_has_single_bit_ Ns Em type Ns ()
86family of functions and the
87.Fn stdc_has_single_bit
88type-generic macro conform to
89.St -isoC-2023 .
90.Sh HISTORY
91The
92.Nm stdc_has_single_bit_ Ns Em type Ns ()
93family of functions and the
94.Fn stdc_has_single_bit
95type-generic macro were added in
96.Fx 15.1.
97.Sh AUTHOR
98.An Robert Clausecker Aq Mt fuz@FreeBSD.org
99