xor (boolean a, boolean b) ⇒ boolean
Returns the exclusive-or (XOR) on two boolean values. i.e. !($a && $b) && ($a || $b).
First available: Version 1.4.3
Notes
XOR (⊕) is based on the logic that is provided by underlying logic gates made of transistors. As such, XOR is true if and only if one condition is true. The truth table for OR and XOR is shown below:
| P | Q | P ∨ Q | P ⊕ Q |
|---|---|---|---|
| True | True | True | False |
| True | False | True | True |
| False | True | True | True |
| False | False | False | False |
Using XOR to construct a 1 bit adder
YASS
function adder($a, $b, $c) $sum = xor(xor($a, $b), $c) $carry = (xor($a, $b) and $c) or ($a and $b) return ["result" => $sum, "carry" => $carry] end function function main() print(adder(1, 0, 0)) print(adder(0, 0, 1)) print(adder(1, 1, 0)) end function
For more on adders, visit this page.

There are no comments on this page.
Comments are welcome and encouraged, including disagreement and critique. However, this is not a space for abuse. Disagreement is welcome; personal attacks, harassment, or hate will be removed instantly. This site reflects personal opinions, not universal truths. If you can’t distinguish between the two, this probably isn’t the place for you.
Comments powered by BalfComment