Boolean Calculator

Boolean Logic Calculator

Use this calculator to evaluate common boolean logic operations based on two input values (A and B).

(Checked = True, Unchecked = False)
(Checked = True, Unchecked = False)
AND (A & B) OR (A | B) XOR (A ^ B) NAND (NOT (A & B)) NOR (NOT (A | B)) NOT A (!A) NOT B (!B)

Result:

Please select inputs and an operation, then click Calculate.

Understanding Boolean Logic

Boolean logic, named after mathematician George Boole, is a fundamental branch of algebra that deals with variables that can only have two possible values: true or false (often represented as 1 or 0). It's the bedrock of all digital electronics, computer science, and programming.

Key Concepts:

  • Boolean Variables: These are variables that can only hold one of two states: True (1) or False (0).
  • Logic Gates: These are elementary building blocks of digital circuits that implement boolean functions. Common gates include AND, OR, NOT, XOR, NAND, and NOR.
  • Truth Tables: A truth table is a mathematical table used in logic to compute the functional values of logical expressions on each of their functional arguments, that is, on each combination of truth values taken by their sentential variables.

Common Boolean Operations:

This calculator supports the following operations:

  • AND (Conjunction): The output is True only if ALL inputs are True. Otherwise, the output is False.
    Example: If A is True and B is True, A AND B is True. If A is True and B is False, A AND B is False.
  • OR (Disjunction): The output is True if AT LEAST ONE input is True. The output is False only if ALL inputs are False.
    Example: If A is True and B is False, A OR B is True. If A is False and B is False, A OR B is False.
  • NOT (Negation): This is a unary operation (takes only one input). It reverses the truth value of its input. If the input is True, the output is False, and vice-versa.
    Example: If A is True, NOT A is False. If A is False, NOT A is True.
  • XOR (Exclusive OR): The output is True if the inputs are DIFFERENT. The output is False if the inputs are the SAME.
    Example: If A is True and B is False, A XOR B is True. If A is True and B is True, A XOR B is False.
  • NAND (NOT AND): The output is the opposite of an AND gate. It is False only if ALL inputs are True. Otherwise, the output is True.
    Example: If A is True and B is True, A NAND B is False. If A is True and B is False, A NAND B is True.
  • NOR (NOT OR): The output is the opposite of an OR gate. It is True only if ALL inputs are False. Otherwise, the output is False.
    Example: If A is False and B is False, A NOR B is True. If A is True and B is False, A NOR B is False.

How to Use the Calculator:

  1. Set Input A: Check the box for Input A if you want it to be True, or leave it unchecked for False.
  2. Set Input B: Check the box for Input B if you want it to be True, or leave it unchecked for False.
  3. Select Operation: Choose the boolean operation you wish to perform from the dropdown menu (e.g., AND, OR, XOR).
  4. Calculate: Click the "Calculate" button to see the result of the chosen operation based on your inputs.

Examples:

  • Example 1: A is True, B is False, Operation: AND
    Set Input A (checked), Input B (unchecked). Select "AND".
    Result: False (Because for AND, both must be True).
  • Example 2: A is False, B is True, Operation: OR
    Set Input A (unchecked), Input B (checked). Select "OR".
    Result: True (Because for OR, at least one must be True).
  • Example 3: A is True, B is True, Operation: XOR
    Set Input A (checked), Input B (checked). Select "XOR".
    Result: False (Because for XOR, inputs must be different).
  • Example 4: A is False, B is True, Operation: NOT B
    Set Input A (unchecked), Input B (checked). Select "NOT B".
    Result: False (The NOT operation reverses B's value from True to False).
.boolean-calculator-container { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: #f9f9f9; border: 1px solid #ddd; border-radius: 8px; padding: 25px; max-width: 700px; margin: 20px auto; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08); } .boolean-calculator-container h2 { color: #333; text-align: center; margin-bottom: 20px; font-size: 2em; } .boolean-calculator-container h3 { color: #555; margin-top: 25px; margin-bottom: 15px; font-size: 1.5em; border-bottom: 1px solid #eee; padding-bottom: 5px; } .boolean-calculator-container p { color: #666; line-height: 1.6; margin-bottom: 10px; } .calculator-form .form-group { margin-bottom: 15px; display: flex; align-items: center; gap: 10px; } .calculator-form label { flex: 0 0 100px; color: #444; font-weight: bold; } .calculator-form input[type="checkbox"] { transform: scale(1.2); margin-right: 5px; } .calculator-form select { flex-grow: 1; padding: 10px; border: 1px solid #ccc; border-radius: 5px; font-size: 1em; max-width: 250px; } .calculator-form button { display: block; width: 100%; padding: 12px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px; font-size: 1.1em; cursor: pointer; transition: background-color 0.3s ease; margin-top: 20px; } .calculator-form button:hover { background-color: #0056b3; } .calculator-result { background-color: #e9f7ef; border: 1px solid #d4edda; border-radius: 5px; padding: 15px; margin-top: 25px; text-align: center; } .calculator-result h3 { color: #28a745; margin-top: 0; margin-bottom: 10px; font-size: 1.4em; border-bottom: none; padding-bottom: 0; } .calculator-result p { color: #155724; font-size: 1.2em; font-weight: bold; } .calculator-article ul { list-style-type: disc; margin-left: 20px; color: #666; } .calculator-article ol { list-style-type: decimal; margin-left: 20px; color: #666; } .calculator-article li { margin-bottom: 8px; } .calculator-article li strong { color: #333; } function calculateBoolean() { var inputA = document.getElementById("inputA").checked; var inputB = document.getElementById("inputB").checked; var operation = document.getElementById("operationSelect").value; var result; switch (operation) { case "AND": result = inputA && inputB; break; case "OR": result = inputA || inputB; break; case "XOR": result = (inputA && !inputB) || (!inputA && inputB); break; case "NAND": result = !(inputA && inputB); break; case "NOR": result = !(inputA || inputB); break; case "NOT_A": result = !inputA; break; case "NOT_B": result = !inputB; break; default: result = "Invalid Operation"; } document.getElementById("booleanResult").innerHTML = "" + (result === true ? "True" : (result === false ? "False" : result)) + ""; }

Leave a Reply

Your email address will not be published. Required fields are marked *