当前位置: C语言 -- 标准库 -- <stdbit.h> -- stdc_count_ones_ul

stdc_count_ones_ul函数


概要:
#include <stdbit.h>
unsigned int stdc_count_ones_ul(unsigned long int value) [[unsequenced]];

描述:

该函数计算参数value中1位的数量;例如:假设unsigned long int类型占4个字节,如果参数value值为0X13U,1位的数量是3。

unsequenced类型属性表示:stdc_count_ones_ul函数是无状态、无副作用、幂等、并且是独立的。


参数:
unsigned long int value

参数为unsigned long int类型对象。


返回值:

该函数返回参数value中1位的数量。


范例:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
/*函数stdc_count_ones_ul范例*/

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

int main(void)
{
    unsigned long int value = 0X13U;

    printf("The total number of 1 bits: %u\n", stdc_count_ones_ul(value));

    return 0;
}

可能输出:

The total number of 1 bits: 3

(注:编译时实现未支持<stdbit.h>头文件。)


相关内容:
stdc_count_ones_uc 计算unsigned char类型对象1位数量的函数。
stdc_count_ones_ui 计算unsigned int类型对象1位数量的函数。
stdc_count_ones_us 计算unsigned short类型对象1位数量的函数。
stdc_count_ones_ull 计算unsigned long long int类型对象1位数量的函数。
stdc_count_ones 计算1位数量的泛型函数。


主要参考资料:

1、ISO/IEC 9899:2024