C语言中的位设置等几个有趣的函数

来源:互联网 发布:广西软件开发 编辑:程序博客网 时间:2024/04/29 07:48

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


0 0
原创粉丝点击