Sum vs XOR

  • + 0 comments

    My Solution in java8:

    public static long sumXor(long n) {
    // Write your code here
    Long res = 0L, nn = n;
    res = (long)Math.pow(2,(Long.toBinaryString(nn).chars().filter(x -> x == '0').count()));
    return n == 0 ? 1 : res;
    }