summaryrefslogtreecommitdiff
path: root/lib/libc/stdbit/stdc_has_single_bit.c
blob: a448464b04d9f16ff5c70d51d72e42a75fab10e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
 * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <stdbit.h>
#include <stdbool.h>

bool
stdc_has_single_bit_uc(unsigned char x)
{
	return (x != 0 && (x & (x - 1)) == 0);
}

bool
stdc_has_single_bit_us(unsigned short x)
{
	return (x != 0 && (x & (x - 1)) == 0);
}

bool
stdc_has_single_bit_ui(unsigned int x)
{
	return (x != 0 && (x & (x - 1)) == 0);
}

bool
stdc_has_single_bit_ul(unsigned long x)
{
	return (x != 0 && (x & (x - 1)) == 0);
}

bool
stdc_has_single_bit_ull(unsigned long long x)
{
	return (x != 0 && (x & (x - 1)) == 0);
}