in reply to logical Exclusive Or, xor

I think that xor in a non binary sense is just there for completeness. I cant think of any times ive seen it in use in programming, but having said that I can think of a few places I might've used it had I realised it was there. (thanks, I knew it was there for bitwise use, but wasnt aware it was also available for logical use.)

Where is binary XOR used? Well, binary adders are usually made up of a bunch of XOR's. (Or used to be anyway... :-)

Also, it wouldnt suprise me if you went through your code that you might find a few implict xors. As xors can be constructed out of the other gates you may have used one inadverdantly without realizing.

my @a=(0,0,1,1); my @b=(0,1,0,1); print " | _ +__________ \n"; print " | _ _ ___ ___ ___ ___ + ___ \n"; print " A B | A B (A&B) (A|B) (AxB) (A&B) (A|B) (AxB) ((A|B)&(A&B)) (( +A&B)|(A|B))\n"; print "-----+--------------------------------------------------------- +-----------\n"; for (0..3) { printf" %d %d | %d %d %d %d %d %d %d %d +%d %d \n", $a[$_], $b[$_], ($a[$_]?0:1), ($b[$_]?0:1), ($a[$_] and $b[$_]), ($a[$_] or $b[$_]), ($a[$_] xor $b[$_]), (($a[$_] and $b[$_])?0:1), (($a[$_] or $b[$_])?0:1), (($a[$_] xor $b[$_])?0:1), ((($a[$_] or $b[$_]) and ($a[$_] and $b[$_])?0:1)), ((($a[$_] and $b[$_]) or ($a[$_] or $b[$_])?0:1)?0:1); } __END__ | ________ +___ | _ _ ___ ___ ___ ___ _ +__ A B | A B (A&B) (A|B) (AxB) (A&B) (A|B) (AxB) ((A|B)&(A&B)) ((A&B)|(A +|B)) -----+---------------------------------------------------------------- +---- 0 0 | 1 1 0 0 0 1 1 1 0 0 0 1 | 1 0 0 1 1 1 0 0 1 1 1 0 | 0 1 0 1 1 1 0 0 1 1 1 1 | 0 0 1 1 0 0 0 1 0 0
So any time you have written ($x || $y && !($x && $y)) you could have used $x xor $y.

Incidentally, a little piece of trivia, xor is not only interesting due to its arithmetical properties, but also for the following fact: xor/xnor are the only (named)(useful) binary gates that _cannot_ be used to construct the rest. There are the unnamed gates (output 0101 and its complement 1010, and output 1100 and complement 0011) that share this fault, but afaik they arent used at all (and actually they simplify down to not(A) and not(B) and so theres no suprise there.) All of the rest when combined with not can be used to construct the rest, with NOR and NAND being particularly useful as they have no need for the supporting not gates. ( A NOR A=NOT A, A NAND A = NOT A )

Hope this wasnt too OT for you, I always found logic gates to be fascinating things, (until I did a symbolic logic class and saw the horrible things that philosophers like to do with them... And never an XOR gate to be seen.... Upside down truth tables, funny symbols, grumble grumble grumble)

:-)

--- demerphq
my friends call me, usually because I'm late....