Chinaunix首页 | 论坛 | 博客
  • 博客访问: 268881
  • 博文数量: 61
  • 博客积分: 655
  • 博客等级: 上士
  • 技术积分: 489
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-21 18:21
文章分类

全部博文(61)

文章存档

2014年(9)

2013年(23)

2012年(26)

2011年(3)

我的朋友

分类: LINUX

2013-12-12 16:20:47

Linux ffs()函数

   ffs()函数用于查找一个整数中的第一个置位值(也就是bit为1的位)。
   函数原型:
   #include
   int ffs(int i);
   下面举个例子:    
      

#include
#include
int main()
{
int num[]={0,1,2,4,8,16,32,64};
int j;
for(j=0;j<8;j++)
printf("%d :%d \n",num[j],ffs(num[j]));
}

书上的运行结果为:

0 :0

1:1

2:2

4:3

8:4

16:5

32:6

64:7


注:这个函数用的好像不多哦~
阅读(3826) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~