[H-GEN] Mysql & bitwise xor

Greg Black gjb at gbch.net
Mon Nov 17 19:57:16 EST 2003


[ Humbug *General* list - semi-serious discussions about Humbug and     ]
[ Unix-related topics. Posts from non-subscribed addresses will vanish. ]

On 2003-11-18, Raymond Smith wrote:
> Greg Black said:
> > On 2003-11-17, Paul Clarke wrote:
> >> So, the next question is what is the logic needed to do an xor using
> >> only &, |, and ~ (and, or, and not)?
> >
> > Have you tried substituting X | ~Y for X ^ Y?
> 
> Should that not be '(X & ~Y) | (~X & Y)' or '~((X&Y) | (~X&~Y))'?

It was a pedagogical answer, not a solution on a plate.

The way to read it is like this:

    Why not carry out some direct research into the question
    yourself?  The sort of thing you might try is substituting
    "foo" for "bar".  From there you could, armed with the basic
    rules of Boolean logic, quickly establish what combinations
    of operators might do what you need.

Of course, Boolean logic is so simple that I could teach it to
any ordinarily intelligent person in five minutes, so I assume
that the OP has mastered it (else why try to use it?).  Even if
one does not happen to carry in one's head the set of rules that
allow one to build specific operators from others, working out
the ones you need is quite trivial.

And then, as part of this pedagogical process, if the OP worked
out what to do and then ran into trouble, he could come back
with a question framed a bit like this:

    My reading of Foobar's book on Boolean logic tells me that I
    can use (some expression) to do (something).  But, when I do
    "this operation", I get "this result" when I expected "this
    other result" -- where have I gone wrong?

Somehow, I thought I had conveyed all of the above in my one
line response :-)

And, by intent, I have still not stated just what is the answer
to the original question.

> Or is this some sort of limitation with these SQL operators?

As with all Boolean operators, the full glorious set is larger
than what is strictly needed to accomplish all operations.  I
expect, but have no intention of verifying, that you'd discover
that (even with the missing XOR operator and any others that it
might not provide) MySQL probably allows you to construct all
the variations you need.  If not, then that's a bug in the MySQL
implementation, rather than just a documentation bug as we have
already established.

Cheers, Greg

--
* This is list (humbug) general handled by majordomo at lists.humbug.org.au .
* Postings to this list are only accepted from subscribed addresses of
* lists 'general' or 'general-post'.  See http://www.humbug.org.au/



More information about the General mailing list