Path: utzoo!mnetor!uunet!husc6!ukma!rutgers!mtune!codas!killer!richardh From: richardh@killer.UUCP (Richard Hargrove) Newsgroups: comp.lang.c Subject: Re: "logical" xor Message-ID: <2800@killer.UUCP> Date: 12 Jan 88 03:28:49 GMT References: <2946@zeus.TEK.COM> <195@fxgrp.UUCP> Organization: The Unix(R) Connection, Dallas, Texas Lines: 29 Summary: need logical xor? try != In article <195@fxgrp.UUCP>, ljz@fxgrp.UUCP (Lloyd Zusman, Master Byte Software) writes: > In article <2946@zeus.TEK.COM> dant@tekla.UUCP (Dan Tilque) writes: > > ... > >Tell me, what is the ^^ supposed to add that is not already done by ^ ? > >The answer is nothing. The "bitwise" xor does exactly what you would want > >a "logical" xor to do. In fact, the terms "bitwise" and "logical" are > > I'm sorry, but I disagree. Try running this program: { code and text deleted...} > bit testing, etc. The 'logical' versions are guaranteed to result in > 1 or 0. This topic came up about a year ago. I had found a need for a logical xor operator a couple of times and added my _naive_ voice to the clamor to add it to C. A number of folks graciously pointed out that logical xor operator (and its complement, logical equivalence) already exist in C: they are != and == used with pure "boolean" operands (canonical TRUE and FALSE, 1 and 0) and that any numeric operand can be converted to canonical "boolean" form with the != operator. Therefore ((x != 0) != (y != 0)) is the logical xor of x and y. richard hargrove ...!killer!richardh -------------------