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....


In reply to Re: logical Exclusive Or, xor by demerphq
in thread logical Exclusive Or, xor by fruiture

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.