Computer Science Fundamentals
Boolean Logic
An AND gate outputs 1 in which case?
Pick one answer
Computer Science Fundamentals
Pick one answer
AND, OR and NOT — the three operations every circuit and every condition is built from.
An AND gate outputs 1 in which case?
Options
Answer: Only when both inputs are 1
Why: AND demands both conditions at once, so a single 0 on either input forces the output to 0. Option A describes OR, and option D describes XOR. In code this is the same operator that makes a guard clause require every check to pass.
Hint: Read it as the everyday word "and".
How many rows does a truth table with three inputs have?
Answer: 8 rows
Why: Three independent inputs give 2 × 2 × 2 = 8 combinations, from 000 to 111. Truth tables double with every added input, which is why exhaustive testing of a condition with twenty flags is already out of reach at over a million rows.
Hint: Each input is either 0 or 1, independently.
Which expression is equivalent to NOT (A AND B)?
Options
Answer: (NOT A) OR (NOT B)
Why: De Morgan's law says a negated AND becomes an OR of negations. "Not both" is true whenever at least one of them fails, which is exactly (NOT A) OR (NOT B). Option A says neither holds, a strictly stronger claim. Applying this law is how tangled conditions get simplified in real code.
Hint: Negate each part and flip the connective between them.
Which gate outputs 1 exactly when its two inputs are different?
Options
Answer: XOR
Why: XOR is exclusive OR: true for 0-1 and 1-0, false for 0-0 and 1-1. Ordinary OR also returns 1 when both inputs are 1, which is the difference between them. XOR is what powers parity checks, simple encryption and the addition step inside a binary adder.
Hint: Plain OR also accepts the case where both inputs are 1.
Which single gate type can be wired together to build every other gate?
Options
Answer: NAND
Why: Feeding the same signal into both inputs of a NAND gives NOT. A NAND followed by that NOT gives AND, and negating both inputs of a NAND gives OR — so everything else follows. Plain AND and OR can never produce a negation, so they cannot be universal. Chip designers exploit this by manufacturing vast fields of one gate type.
Hint: You need a gate that can produce a NOT on its own.