CS:APP 第三版 第二章家庭作业
2019-09-20 19:18
1201 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/HolmiumJiang/article/details/101074596
2.64
int any_odd_one(unsigned x){ unsigned msk=0x55555555; return (x&msk)!=0; }
2.65
int odd_one(unsigned x){ int b1=1; int b2=2; int b3=4; int b4=8; int b5=16; x=(x>>b1)^x; x=(x>>b2)^x; x=(x>>b3)^x; x=(x>>b4)^x; x=(x>>b5)^x; return (x&1)!=0; }
2.66
int leftmost_one(unsigned x) { x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; x ^= x >> 1; return x; }
2.68
int lower_one_mask(int n){ unsigned ans=(unsigned)-1; size_t x=sizeof(int)<<3; return (int)((ans<<(x-n))>>(x-n)); }
2.70
int fits_bits(int x,int n){ n-=1; return ((x>>n)==-1)||((x>>n)==0); }
2.73
int saturating_add(int x, int y) { int z, f1, f2, ans, wd; wd = (sizeof(int) << 3) - 1; z = x + y; f1 = ((x >> wd) && (y >> wd) && ~(z >> wd)) || (~(x >> wd) && ~(y >> wd) && (z >> wd)); f2 = (z >> wd) != 0; ans = z ^ ((1 << wd) - f2); ans = ans & (0 - f1); ans = ans ^ z; return ans; }
2.74
int tsub_ok(int x,int y){ int z=x-y; return !(~(x >> wd) && (y >> wd) && (z >> wd)) || ((x >> wd) && ~(y >> wd) && ~(z >> wd)); }
2.79
int mul3div4(int x){ return (x+(x<<1))>>2; }
2.80
int threefourths(int x){ size_t w=sizeof(int)<<3; w=w-1; unsigned fl=~(x>>w); int tmp=x+(fl&3); w=w-1; fl=fl<<w; tmp=(tmp>>2)^fl; //printf("#%x %x\n",tmp,fl); return x-tmp; }
相关文章推荐
- 深入理解计算机系统_3e 第二章家庭作业 CS:APP3e chapter 2 homework
- 深入理解计算机系统_3e 第十章家庭作业 CS:APP3e chapter 10 homework
- 深入理解计算机系统_3e 第十一章家庭作业 CS:APP3e chapter 11 homework
- 深入理解计算机系统_3e 第七章家庭作业 CS:APP3e chapter 7 homework
- 深入理解计算机系统_3e 第五章家庭作业 CS:APP3e chapter 5 homework
- 深入理解计算机系统_3e 第六章家庭作业 CS:APP3e chapter 6 homework
- 深入理解计算机系统_3e 第四章家庭作业(部分) CS:APP3e chapter 4 homework
- 深入理解计算机系统_3e 第八章家庭作业 CS:APP3e chapter 8 homework
- 深入理解计算机系统_3e 第三章家庭作业 CS:APP3e chapter 3 homework
- Google Web App开发指南第二章:交互设计
- 在WinForm的cs文件中使用app.config里的connection string
- 读书笔记《深入理解计算机系统》(第三版) 第二章 信息的表示
- 深入理解计算机系统(第三版)第2章 家庭作业
- 深入理解计算机系统(第三版)第3章 家庭作业
- CS-APP:Section 5.1,Memory aliasing :看上去逻辑一样,执行结果一样吗?
- 为什么vs2005建立的cs类要放在app_code文件夹才能在其他页面用?
- app.g.cs的显示问题
- Graduation_App_Code/WebService.cs
- CS:APP3e 深入理解计算机系统_3e bomblab实验