Skip to content
Tactiverge

Digital logic

AND gate

Also called: AND · conjunction · A·B · both inputs

Definition

An AND gate outputs 1 only when all of its inputs are 1.

Picture it

Two switches in series: the lamp lights only if both are closed. Safety interlocks are AND logic: the motor runs only if the guard is shut AND the start button is pressed. AND with a mask is also how firmware picks out particular bits.

The maths

Y = A · B
A B | Y: 00|0 01|0 10|0 11|1
SI units used in this entry
QuantityUnitSymbol
ratiodimensionless1

Worked example

A status register reads 0b1011 0110. Firmware ANDs it with the mask 0b0000 0100 to test bit 2. What is the result?

  1. 1011 0110 AND 0000 0100
  2. Only bit 2 survives, and it is 1 → 0000 0100 = 4
  3. Non-zero, so bit 2 is set

Answer0000 0100 (decimal 4): bit 2 is set.

✓ The number in this answer is recomputed from scratch by an automated test.

logic tester

Logic gate tester

Y = 1

Y = A ⊕ B

Truth table for XOR; the current row is marked.
ABY
000
011
101 ◀ now
110
XOR with A = 1, B = 0 gives Y = 1.

Ideal gates: no propagation delay. 1 = true = high, 0 = false = low.

Common misconceptions

  • Misconception: Logical and (a and b) and bitwise & (a & b) are different operations in Python.
  • Misconception: An AND gate with one input at 0 ignores the other input entirely.