Data in computers (or any digital electronic device) is represented in Binary Bits and Bytes. Basically 0 or 1. But how do computers change data? Without going into too much detail, computers do so by way of binary logic.

Below is a list of all the operations that can be done. Example outputs are assuming either one or two inputs. Multiple inputs of the same logic gate can be reduced to a chain of two-input versions.

# The operations

**NOT**: Inverts the incoming signal.

- Usually written as a leading exclamation mark, tilde, or ¬.
- For example !X or ~X.

Input | 0 | 1 |

Output | 1 | 0 |

**OR**: As long as one input is 1, the output is 1.

- Usually written using one or two pipe characters, +, or v.
- For example, X | Y or X || Y.

- Can be thought of as addition, only you have to believe for a moment that 1 + 1 = 1.

Input | 00 | 01 | 10 | 11 |

Output | 0 | 1 | 1 | 1 |

**AND**: All inputs must be 1 for the output to be 1.

- Usually written using one or two ampersands,
**⋅**(dot operator) , or ∧- For example, X & Y or X && Y.

- Can be thought of as multiplication.

Input | 00 | 01 | 10 | 11 |

Output | 0 | 0 | 0 | 1 |

**XOR (Exclusive OR)**: For two-input XOR operations, both inputs must be different to output a 1. Otherwise, the number of inputs that are 1 must be odd to output a 1.

- Usually written using a caret or ⊕.
- For example, X ^ Y.

- Can be thought of subtraction, only the result is the always positive.

Input | 00 | 01 | 10 | 11 |

Output | 0 | 1 | 1 | 0 |

**NAND**: If all inputs are 1, the output is 0; the opposite of AND. This is one of the universal logic operations, which can create any other logic operation. Most commonly used in Flash Memory.

- Usually written using ↑
- If programming, it would be written as !(X & Y) or similar.

Input | 00 | 01 | 10 | 11 |

Output | 1 | 1 | 1 | 0 |

**NOR**: If any input is 1, the output is 0; the opposite of OR. This is the other universal logic operation and was used in flash memory.

- Usually written using ↓
- If programming, it would be written as !(X | Y) or similar.

Input | 00 | 01 | 10 | 11 |

Output | 1 | 0 | 0 | 0 |

**XNOR**: For two-input operation, all inputs must be the same to output a 1; the opposite of a XOR. Otherwise the number of inputs that are 1 must be even to output a 1.

- Outside of computing, it's often written as "iff", for "if and only if", because one is true
*if and only if*the other one is too. This makes it useful as a voter gate (i.e., both inputs must agree before giving an output)

Input | 00 | 01 | 10 | 11 |

Output | 1 | 0 | 0 | 1 |

# Supplemental Operations

**Three-state Buffer**: A buffer (input = output) with a second input that, when enabled, cuts the signal off in a state known as Hi-Z. The rest of the system sees this as "disconnected". As an example, if you had a motor control, 0 could be reverse, 1 could be forward, and Hi-Z could be off.

Input | X | 0 | 1 |

Disable | 1 | 0 | 0 |

Output | Hi-Z | 0 | 1 |

**Latch**: A latch is a fundamental "storage unit", made with a pair of NOR or NAND gates with the outputs feeding one of the other's inputs, as well as providing an actual output. This produces a pair of opposite outputs. Since there are two outputs, usually only one of them is used. The other can be used to avoid using a NOT gate if the signal's negative is needed. Latches also can produce an invalid result if its input is 00 or 11 depending on the type. This is due to the outputs equally each other when they should be different. If a latch takes a clock signal as an input, it's called a flip-flop instead.

For a Set-Reset latch, the output is:

Input (Set) | 0 | 0 | 1 | 1 |

Input (Reset | 0 | 1 | 0 | 1 |

Output (Q) | (no change) | 0 | 1 | 0 |

Output (Q-not) | (no change) | 1 | 0 | 0 |

Note in this example for inputs 11, it produces the output 00, which makes Q = Q-not.