Hacker's Delight
传到桥头必然沉
这个作者很懒,什么都没留下…
展开
-
Manipulating Rightmost Bits--come from Hacker's Delight
2–1 Manipulating Rightmost BitsSome of the formulas inthis section find application in later chapters.Use the followingformula to turn off the rightmost1-bit in a word, producing 0 if none (e.g.,翻译 2016-12-12 21:43:53 · 422 阅读 · 0 评论 -
逻辑运算小结1---和X拥有的1的个数相同,但是比X大的第一个数的求解方法
#include using namespace std;//和X拥有的1的个数相同,但是比X大的第一个数的求解方法:unsigned snoob(unsigned x) //举例: X = 0000 1111 00000{ unsigned smallest, ripple, ones; // x = 0000 1111 0000 smallest原创 2016-12-12 22:17:51 · 289 阅读 · 0 评论 -
位运算小结2---计算两个无符号整数的平均值
#include using namespace std;//位运算求解两个数的平均数unsigned AverageOfTwoIntegers(unsigned x, unsigned y){ return (x&y) + ((x^y)>>1);}int main(){ unsigned int x, y; cin>>x>>y; cout原创 2016-12-12 22:33:32 · 637 阅读 · 0 评论 -
逻辑位运算小结3——求x|y最小值
通信原理考试挂了,郁闷。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。直接上代码;测试通过#include using namespace std;//已知a<=x<=b , c<=y<=d, 求解x|y的最小值unsigned MinOr(unsigned a, unsigned b, unsigned c, unsigned d ){ unsig原创 2016-12-21 21:39:42 · 343 阅读 · 0 评论 -
逻辑位运算小结4--x|y的最大值
已知a挂科让人很伤心整的我现在做什么都没有心情#include using namespace std;//已知a<=x<=b , c<=y<=d, 求解x|y的最大值unsigned MaxOr(unsigned a, unsigned b, unsigned c, unsigned d ){ unsigned m, tmp; m = 0x800000原创 2016-12-21 21:48:23 · 591 阅读 · 0 评论 -
逻辑位运算小结5
挂科了,心情不好,直接贴代码//已知a<=x<=b , c<=y<=d, 求解x&y的最大值unsigned MaxAnd(unsigned a, unsigned b, unsigned c, unsigned d ){ unsigned m, tmp; m = 0x80000000; while ( m != 0 ) { if( b原创 2016-12-21 22:00:10 · 243 阅读 · 0 评论 -
逻辑位运算小结6
//计算无符号整形x(二进制)中有多少位是1int NumOfOneBit_1(unsigned x ){ x = x - ( (x>>1) & 0x55555555 ); x = ( x & 0x33333333 ) + ( (x>>2) & 0x33333333 ); x = ( x + (x>>4) ) & 0x0f0f0f0f; x = x + ( x原创 2016-12-21 22:25:43 · 262 阅读 · 0 评论