约 1557 字

约 8 分钟

#C 语言标准库函数 stdc_has_single_bit_us

#include <stdbit.h>

bool stdc_has_single_bit_us(unsigned short value) [[unsequenced]];

说明

确定是否只有一个值位为 1。

只处理输入类型的值位。

自 C23 起提供。

参数

  • value - unsigned short 类型的输入。

返回值

  • 返回 bool 类型的判断结果。 只有一个位为 1 等价于输入为正的 2 的整数次幂。零返回 false。

#示例

#include <stdbit.h>
#include <stdio.h>

int main(void)
{
    unsigned short value = (unsigned short)32;
    printf("%llu\n", (unsigned long long)stdc_has_single_bit_us(value));
    return 0;
}

运行结果。

1

#相关接口

#参考标准

更新: 2026/11/28

作者: planc

创建: 2026/11/28