Generate mask indicating leftmost 1 in x.
2013-10-15 00:00
1631 查看
摘要: For example 0xFF00 -> 0x8000,and 0x6600 -> 0x4000.If x = 0 ,then return 0.
int leftmost_one(unsigned x);
函数应该遵循位级编码规则,不过代可以假设数据类型int 有w = 32位。
你的代码最多只能包含15个算术运算、位运算和逻辑运算.
来自<深入理解计算机系统>第二章 66
代码如下:
int leftmost_one(unsigned x){
x = x | (x >> 1);
x = x | (x >>2);
x = x | (x >>4);
x = x | (x >> 8);
x = x | (x >> 16);
printf("%x\n",x);
return x ^(x >> 1);
}
int leftmost_one(unsigned x);
函数应该遵循位级编码规则,不过代可以假设数据类型int 有w = 32位。
你的代码最多只能包含15个算术运算、位运算和逻辑运算.
来自<深入理解计算机系统>第二章 66
代码如下:
int leftmost_one(unsigned x){
x = x | (x >> 1);
x = x | (x >>2);
x = x | (x >>4);
x = x | (x >> 8);
x = x | (x >> 16);
printf("%x\n",x);
return x ^(x >> 1);
}
相关文章推荐
- matlab 标定箱错误:Disabling view 2 - Reason: the left and right images are found inconsistent (已解决)
- Mask RCNN in TensorFlow
- Tag, Tag group and Tag mask in Cell BE
- hdu_2.1.8_Leftmost Digit
- 报错: chaser.rb:35 in `join': No live threads left.&
- 托福写作5-what is the most important characteristic that a person can have to be successful in life
- [AtCoder AGC002 F][DP]Leftmost Ball
- X++ CODE TO GENERATE ALERT FOR RECORD IN DAX 2011
- 对display:inline;与float:left;的认识
- python安装setuptools报错Traceback (most recent call last): File "setup.py", line 11, in <module> i
- 杭电 1060 Leftmost Digit
- Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection
- 对display:inline与float:left正确含义的认识!
- How to generate a random alpha-numeric string in java
- hdu 1060 Leftmost Digit
- Uncaught ReferenceError: Invalid left-hand side in assignment
- Android坐标getLeft,getRight,getTop,getBottom,getLocationInWindow和getLocationOnScreen
- 操作系统常见面试题整理(Most Common Problems in Interview for Operating System)
- Leftmost Digit
- SQL语句使用Left Outer join代替In删除多条记录