Xor: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
No edit summary
(Added javascript snippet)
Line 5: Line 5:
Xor returns the logical, exclusive disjunction of two expressions. ''result'' is TRUE, if and only if one of the expressions ''x'' and ''y'' evaluate to TRUE, otherwise, ''result'' is FALSE.
Xor returns the logical, exclusive disjunction of two expressions. ''result'' is TRUE, if and only if one of the expressions ''x'' and ''y'' evaluate to TRUE, otherwise, ''result'' is FALSE.


== Example ==
== Example (Basic) ==


<pre>
<pre>
Rem Xor Example
Rem Xor Example
'Xor performs exclusive disjunctions
'Xor performs exclusive disjunctions
Dim Test1, Test2, x, y
Dim Test1, Test2, x, y
x = 2
x = 2
y = 9
y = 9
Test1 = x > 0 Xor y < 10
Test1 = (x > 0) Xor (y < 10)
Test2 = x > 0 Xor y > 10
Test2 = (x > 0) Xor (y > 10)
Print "Logical:"
Print "Logical:"
Print "  x > 0 Xor y < 10 = " & CStr(Test1)
Print "  (x > 0) Xor (y < 10) = " & CStr(Test1)
Print "  x > 0 Xor y > 10 = " & CStr(Test2)
Print "  (x > 0) Xor (y > 10) = " & CStr(Test2)
</pre>
 
== Example (JavaScript) ==
 
<pre>
// Xor Example
/* Xor performs exclusive disjunctions */
 
var Test1, Test2, x, y;
x = 2;
y = 9;
Test1 = ((x > 0) ^ (y < 10)) == 1;
Test2 = ((x > 0) ^ (y > 10)) == 1;
document.write("Logical:<br>");
document.write("  (x > 0) Xor (y < 10) = " + Test1.toString() + "<br>");
document.write("  (x > 0) Xor (y > 10) = " + Test2.toString() + "<br>");
</pre>
</pre>


Line 24: Line 41:
<pre>
<pre>
Logical:
Logical:
   x > 0 Xor y < 10 = False
   (x > 0) Xor (y < 10) = False
   x > 0 Xor y > 10 = True
   (x > 0) Xor (y > 10) = True
</pre>
</pre>



Revision as of 04:33, 12 May 2013

result = x Xor y

Description

Xor returns the logical, exclusive disjunction of two expressions. result is TRUE, if and only if one of the expressions x and y evaluate to TRUE, otherwise, result is FALSE.

Example (Basic)

Rem Xor Example
'Xor performs exclusive disjunctions

Dim Test1, Test2, x, y
x = 2
y = 9
Test1 = (x > 0) Xor (y < 10)
Test2 = (x > 0) Xor (y > 10)
Print "Logical:"
Print "  (x > 0) Xor (y < 10) = " & CStr(Test1)
Print "  (x > 0) Xor (y > 10) = " & CStr(Test2)

Example (JavaScript)

// Xor Example
/* Xor performs exclusive disjunctions */

var Test1, Test2, x, y;
x = 2;
y = 9;
Test1 = ((x > 0) ^ (y < 10)) == 1;
Test2 = ((x > 0) ^ (y > 10)) == 1;
document.write("Logical:<br>");
document.write("  (x > 0) Xor (y < 10) = " + Test1.toString() + "<br>");
document.write("  (x > 0) Xor (y > 10) = " + Test2.toString() + "<br>");

Output

Logical:
  (x > 0) Xor (y < 10) = False
  (x > 0) Xor (y > 10) = True

Related Items

And, Eqv, Imp, Not, Or