Is it me, or does cj's code return the inverse of the xor result?
if $A = %1010
$B = %1100
then =====
$A xor $b = %0110

so I think the code should be:
$Z = ($A | $B) & (-1 -($A & $B))