C语言中的位设置等几个有趣的函数
最近在复习C 的时候看这样的一个题目:
- /*Decclarations of functions and implementing operations bis and bic*/
- int bis(int x,int m);
- int bic(int x,int m);
- /*compute x|y using only calls to functions bis and bic*/
- int bool_or(int x,int y)
- {
- int result = bis(x,y);
- return result;
- }
- /*compute x^y using only calls to functions bis and bic*/
- int bool_xor(int x,int y)
- {
- int result = bis(bic(x,y),bic(y,x));
- return result;
- }
绝妙的想法,哈哈,大家也要学一学呀!
- int bic(int x,int y);//位清零
- x^y=(x&~y)|(~x&y);