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

stdc_first_trailing_one_ull函数


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

描述:

最低有效索引(the least significant index)是从最低有效位开始计数的、从0至w-1的索引;其中最低有效位索引值为0,最高有效位索引值为w-1,w是正在计算其最低有效索引的类型的位宽。


该函数计算参数value中首个1位的最低有效索引值加1的结果;如果不存在1位,结果为0;例如:假设unsigned long long int类型占8个字节,如果参数value值为0X5A00000000000000U,结果是58。

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


参数:
unsigned long long int value

参数为unsigned long long int类型对象。


返回值:

该函数返回参数value中首个1位的最低有效索引值加1的结果;如果不存在1位,结果为0。


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

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

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

    printf("The least significant index of the first 1 bit plus 1: %u\n", \
    stdc_first_trailing_one_ull(value));

    return 0;
}

可能输出:

The least significant index of the first 1 bit plus 1: 58

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


相关内容:
stdc_first_trailing_one_uc 确定unsigned char类型对象首个尾随1的函数。
stdc_first_trailing_one_us 确定unsigned short类型对象首个尾随1的函数。
stdc_first_trailing_one_ui 确定unsigned int类型对象首个尾随1的函数。
stdc_first_trailing_one_ul 确定unsigned long int类型对象首个尾随1的函数。
stdc_first_trailing_one 确定首个尾随1的泛型函数。


主要参考资料:

1、ISO/IEC 9899:2024