• + 0 comments

    Or since they are all bitwise operations, just figure it out for 4 cases. If you look at the first part:

    // s = ((a & b) ^ (a | b))
    ((0 & 0) ^ (0 | 0)) == 0 ^ 0 == 0
    ((0 & 1) ^ (0 | 1)) == 0 ^ 1 == 1
    ((1 & 0) ^ (1 | 0)) == 0 ^ 1 == 1
    ((1 & 1) ^ (1 | 1)) == 1 ^ 1 == 0
    

    So you do an equivalent of xoring a number and 'and' that with xoring the number.