Path: utzoo!utgpu!water!watmath!clyde!rutgers!ames!fxgrp!ljz From: ljz@fxgrp.UUCP (Lloyd Zusman, Master Byte Software) Newsgroups: comp.lang.c Subject: Re: "logical" xor Message-ID: <195@fxgrp.UUCP> Date: 10 Jan 88 23:49:20 GMT References: <2946@zeus.TEK.COM> Reply-To: fxgrp!ljz@ames.arpa (Lloyd Zusman, Master Byte Software) Followup-To: <2946@zeus.TEK.COM> dant@tekla.UUCP (Dan Tilque) Organization: FX Development Group, Inc., Mountain View, CA Lines: 55 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 >misnomers. They should be "unoptimized" and "optimized". And there's no >way to optimize an exclusive-or operation. > >The only reason to add ^^ is esthetic. ... > ... I'm sorry, but I disagree. Try running this program: #include main() { int a = 2; int b = 0; int c = 7; printf("a = %d, b = %d, c = %d\n", a, b, c); printf("a & b = %d\n", a & b); printf("a && b = %d\n", a && b); printf("a & c = %d\n", a & c); printf("a && c = %d\n", a && c); printf("a | b = %d\n", a | b); printf("a || b = %d\n", a || b); printf("a | c = %d\n", a | c); printf("a || c = %d\n", a || c); } The results that printed out on my machine are: a = 2, b = 0, c = 7 a & b = 0 a && b = 0 a & c = 2 a && c = 1 a | b = 2 a || b = 1 a | c = 7 a || c = 1 In my opinion, this illustrates the *exact* reason for the two versions of the 'and' and 'or' operators. The 'bitwise' versions are needed for bit testing, etc. The 'logical' versions are guaranteed to result in 1 or 0. ------------------------------------------------------------------------- Lloyd Zusman Master Byte Software Los Gatos, California Internet: fxgrp!ljz@ames.arpa "We take things well in hand." UUCP: ...!ames!fxgrp!ljz