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);