Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/lib/libc/stdbit/stdc_has_single_bit.c
96290 views
1
/*
2
* Copyright (c) 2025 Robert Clausecker <[email protected]>
3
*
4
* SPDX-License-Identifier: BSD-2-Clause
5
*/
6
7
#include <stdbit.h>
8
#include <stdbool.h>
9
10
bool
11
stdc_has_single_bit_uc(unsigned char x)
12
{
13
return (x != 0 && (x & (x - 1)) == 0);
14
}
15
16
bool
17
stdc_has_single_bit_us(unsigned short x)
18
{
19
return (x != 0 && (x & (x - 1)) == 0);
20
}
21
22
bool
23
stdc_has_single_bit_ui(unsigned int x)
24
{
25
return (x != 0 && (x & (x - 1)) == 0);
26
}
27
28
bool
29
stdc_has_single_bit_ul(unsigned long x)
30
{
31
return (x != 0 && (x & (x - 1)) == 0);
32
}
33
34
bool
35
stdc_has_single_bit_ull(unsigned long long x)
36
{
37
return (x != 0 && (x & (x - 1)) == 0);
38
}
39
40