Boolean Calculator

Logic Gate & Boolean Algebra Calculator

TRUE (1) FALSE (0)
TRUE (1) FALSE (0)
AND (A ∧ B) OR (A ∨ B) NOT A (¬A) XOR (A ⊕ B) NAND (¬(A ∧ B)) NOR (¬(A ∨ B)) XNOR (¬(A ⊕ B))
Resulting State:

Understanding Boolean Logic

Boolean logic is the foundation of modern digital electronics and computer programming. It deals with variables that have two possible values: True (1) and False (0). This system was pioneered by George Boole in the mid-19th century and is used to design circuits, write search engine queries, and develop complex algorithms.

Primary Logical Operators

  • AND (Conjunction): Output is True only if both inputs are True. If either input is False, the result is False.
  • OR (Disjunction): Output is True if at least one input is True. It only returns False if both inputs are False.
  • NOT (Inversion): This is a unary operator that flips the bit. If the input is True, the output is False, and vice versa.
  • XOR (Exclusive OR): Output is True only if the inputs are different (one True, one False). If they are the same, the result is False.

Truth Table Reference

A B AND OR XOR
00000
01011
10011
11110

Practical Example

Imagine a security system. The alarm (Output) should sound only if the "System is Armed" (Input A) AND a "Motion Sensor is Triggered" (Input B). If Input A is 1 and Input B is 1, the logic gate returns 1, activating the alarm.

function calculateBoolean() { var a = parseInt(document.getElementById('inputA').value); var b = parseInt(document.getElementById('inputB').value); var op = document.getElementById('logicOp').value; var result; var resultText = ""; var desc = ""; switch(op) { case "AND": result = (a && b) ? 1 : 0; desc = "Result is TRUE only because both inputs are 1."; if (result === 0) desc = "Result is FALSE because one or more inputs are 0."; break; case "OR": result = (a || b) ? 1 : 0; desc = "Result is TRUE because at least one input is 1."; if (result === 0) desc = "Result is FALSE because both inputs are 0."; break; case "NOT_A": result = (a === 1) ? 0 : 1; desc = "NOT operator inverted Input A."; break; case "XOR": result = (a !== b) ? 1 : 0; desc = "Result is TRUE because inputs are different."; if (result === 0) desc = "Result is FALSE because inputs are identical."; break; case "NAND": result = !(a && b) ? 1 : 0; desc = "NAND is the inverse of AND."; break; case "NOR": result = !(a || b) ? 1 : 0; desc = "NOR is the inverse of OR."; break; case "XNOR": result = (a === b) ? 1 : 0; desc = "XNOR is TRUE when inputs match."; break; } resultText = (result === 1) ? "TRUE (1)" : "FALSE (0)"; document.getElementById('logicOutput').innerText = resultText; document.getElementById('logicDescription').innerText = desc; document.getElementById('booleanResult').style.display = 'block'; }

Leave a Comment