Ground Embedded KO Subscribe

Notes / Digital Logic

Logic gates and Boolean algebra

AND, OR, NOT, XOR and De Morgan's laws. Schematics and the conditions in C code follow the same rules.

GROUND EMBEDDED · NOTEDigital Logic 02Logic gates and Boolean algebraANDABY

Basic gates

ABANDORXOR
The outputs of three gates for inputs A and B.
Gate Output is 1 when C operator
AND Both are 1 &, &&
OR At least one is 1 \|, \|\|
NOT The input is 0 ~, !
XOR The two differ ^

With NAND alone, or NOR alone, any logic circuit can be built, and the inside of real chips is made of these gates.

De Morgan's laws

  • NOT(A AND B) = (NOT A) OR (NOT B)
  • NOT(A OR B) = (NOT A) AND (NOT B)

In circuits they are used when handling active-low signals, and in code when inverting a complicated condition. !(ready && !error) is the same as !ready || error.

Where you meet them on schematics

An OR that merges several reset signals into one, a decoder that makes chip-select signals, an XOR that makes a pulse when two signals differ. Even with an MCU, the surrounding circuit often includes small logic-gate chips (the 74 series).

FREE PDFGet the 3 free ebooksIf you want to keep reading this topic as one book: BLDC motor control, serial communication and sensors at book length. PDFs are in Korean.Get them free →