C語言中的位設置等幾個有趣的函數

                      C語言中的位設置等幾個有趣的函數

最近在複習C 的時候看這樣的一個題目:

  1. /*Decclarations of functions and implementing operations bis and bic*/
  • int bis(int x,int m);
  • int bic(int x,int m);

  1. /*compute x|y using only calls to functions bis and bic*/
  2. int bool_or(int x,int y)
  3. {
  4.      int result = bis(x,y);
  5.      return result;
  6. }
  1. /*compute x^y using only calls to functions bis and bic*/
  2. int bool_xor(int x,int y)
  3. {
  4.     int result = bis(bic(x,y),bic(y,x));
  5.     return result;
  6. }

絕妙的想法,哈哈,大家也要學一學呀!

  1. int bic(int x,int y);//位清零
  2. x^y=(x&~y)|(~x&y);


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章