A
Think about addition in base two. Say a=10101 and b=1001. What your operation does is it modifies the bits in your numbers, so if the first bit in a is 1 and the first bit in b is 1 (as is the case above) you can make both 0 by making that bit 1 in x. This is actually the only way you can decrease the resulting sum, so x=1 is an answer above.
Noticing the hint above we now deduce x = a & b where & is bitwise and. So just printing (a^(a&b)) + (b^(a&b)) works, but there's an even nicer formula. We'll leave it up to you to prove that (a^(a&b)) + (b^(a&b)) = a ^ b :)
B
It's hard to use the two valuable switches somewhere in the middle of the matrix, a much wiser choice would be to somehow block the S cell or the F cell. Perhaps you can set both neighbours of S to 1 to force Roger to pick 1.
If we pick the neighbours of S to be 1 we can make the neighbours of F 0 and there would be no way to go from S to F. But this in the worst case takes 4 switches, to get down to 2 switches we can consider the other way around, making the S neighbours 0 and F neighbours 1. There must be a solution of the two with at most two switches and you won't get from S to F since you're forced to pick 1 (or 0) and can't get past the neighbours of F which are opposite.