1.\" 2.\" This file and its contents are supplied under the terms of the 3.\" Common Development and Distribution License ("CDDL"), version 1.0. 4.\" You may only use this file in accordance with the terms of version 5.\" 1.0 of the CDDL. 6.\" 7.\" A full copy of the text of the CDDL should have accompanied this 8.\" source. A copy of the CDDL is also available via the Internet at 9.\" http://www.illumos.org/license/CDDL. 10.\" 11.\" 12.\" Copyright 2024 Oxide Computer Company 13.\" 14.Dd October 27, 2024 15.Dt STDC_HAS_SINGLE_BIT 9F 16.Os 17.Sh NAME 18.Nm stdc_has_single_bit , 19.Nm stdc_has_single_bit_uc , 20.Nm stdc_has_single_bit_us , 21.Nm stdc_has_single_bit_ui , 22.Nm stdc_has_single_bit_ul , 23.Nm stdc_has_single_bit_ull 24.Nd determine if only one bit is set 25.Sh SYNOPSIS 26.In sys/stdbit.h 27.Ft bool 28.Fo stdc_has_single_bit 29.Fa "generic_value_type value" 30.Fc 31.Ft bool 32.Fo stdc_has_single_bit_uc 33.Fa "unsigned char value" 34.Fc 35.Ft bool 36.Fo stdc_has_single_bit_us 37.Fa "unsigned short value" 38.Fc 39.Ft bool 40.Fo stdc_has_single_bit_ui 41.Fa "unsigned int value" 42.Fc 43.Ft bool 44.Fo stdc_has_single_bit_ul 45.Fa "unsigned long value" 46.Fc 47.Ft bool 48.Fo stdc_has_single_bit_ull 49.Fa "unsigned long long value" 50.Fc 51.Sh DESCRIPTION 52The 53.Fn stdc_has_single_bit 54family of functions determines whether the value has only a single bit 55set. 56.Fa value . 57The function returns 58.Dv true 59if there is exactly one bit whose value is set to one in 60.Fa value . 61.Pp 62The 63.Fn stdc_has_single_bit 64function is generic and will operate on all 8, 16, 32, and 64-bit 65unsigned integers; however, it is only available in C23. 66The other functions all operate on a specific integer type, but 67otherwise behave the same and are available regardless of the C language 68version. 69.Sh CONTEXT 70These functions may be called from 71.Sy user , 72.Sy kernel , 73or 74.Sy interrupt 75context. 76.Sh RETURN VALUES 77The functions in the 78.Fn stdc_has_single_bit 79family return 80.Dv true 81if exactly one bit is set in 82.Fa value . 83Otherwise, 84.Dv false 85is returned. 86These functions cannot fail. 87.Sh INTERFACE STABILITY 88.Sy Committed 89.Sh SEE ALSO 90.Xr stdc_has_single_bit 3C , 91.Xr stdc_bit_ceil 9F , 92.Xr stdc_bit_floor 9F , 93.Xr stdc_bit_width 9F , 94.Xr stdc_count_ones 9F , 95.Xr stdc_count_zeros 9F , 96.Xr stdc_first_leading_one 9F , 97.Xr stdc_first_leading_zero 9F , 98.Xr stdc_first_trailing_one 9F , 99.Xr stdc_first_trailing_zero 9F , 100.Xr stdc_leading_ones 9F , 101.Xr stdc_leading_zeros 9F , 102.Xr stdc_trailing_ones 9F , 103.Xr stdc_trailing_zeros 9F 104