How XOR Gates Work. JavaScript Source Code Snippet.

Опубликовано: 02 Июль 2026
на канале: AltComp126
129
0

Most programming languages and assemblers have a XOR operator or instruction. It's very useful to generate shorter code which assigns 0 to a variable or register by applying XOR using its own value. As we have seen, since all bits will be the same by using the same processor register or memory variable as the first and second XOR operands, all bits will be cleared to 0 to indicate that they all had the same values.


javascript:

/* Step 1: We need 2 input variables of at least 1 bit in size. */
var bits_A = 1;
var bits_B = 1;

var OR_0 = bits_A|bits_B; /* Step 2: OR the values of both input variables. */
var NAND_0 = ~(bits_A&bits_B); /* Step 3: AND the values of both variables and negate the bit values of this result. */
var XOR_AND_OUT = OR_0&NAND_0; /* Step 4: Apply AND to the OR and the NAND results. This is the XOR value. */

alert(XOR_AND_OUT);

void(0);