Navigation

    小埋社区

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    与(&)或(|)非(~)实现异或(^)

    编程
    algorithm 算法
    1
    1
    51
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Bruce
      Bruce ACG last edited by

      一道很基础但有点意思的算法题,我的思路是

      int my_xor(int a, int b)
      {
              return (a&~b)|(~a&b);
      }
      

      不过网上还有一种比较奇妙的解法,返回(a|b)&(~a|~b)
      结果确实正确,不过很好奇他怎么想到的...

      1 Reply Last reply Reply Quote 0
      • First post
        Last post
      © 2017-2021 小埋社区 All Rights Reserved | 皖ICP备17016228号-2