Maximizing XOR Discussions | Algorithms | HackerRank
  • + 1 comment

    c++, same complexity, but probably faster on newer processors, although not directly portable:

    #include <climits>
    int maxXor(int a, int b) {
      if(a^=b)
        return ~INT_MIN>>__builtin_clz(a)-1;
      return 0;
    }