# Useful Notes: Binary Logic

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. All operations but "NOT" take in two inputs and spit out one output.

# 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.
- For multi-input OR gates, outputs 1 if at least one input is 1.

Input | 00 | 01 | 10 | 11 |

Output | 0 | 1 | 1 | 1 |

**AND**: Both 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.
- For multi-input AND gates, outputs 1 if all inputs are 1.

Input | 00 | 01 | 10 | 11 |

Output | 0 | 0 | 0 | 1 |

**XOR (Exclusive OR)**: Both inputs must be different for the output to be 1.- Usually written using a caret or ⊕.
- For example, X ^ Y.

- Can be thought of subtraction, only the result is the always positive.
- For multi-input XOR gates, outputs 1 if there are an odd number of 1's.

Input | 00 | 01 | 10 | 11 |

Output | 0 | 1 | 1 | 0 |

**NAND**: Same as the AND operation, but the output is inverted. One of the universal logic operations (you can do any of these operations with NAND gates). Most commonly used in Flash Memory.- Usually written using ↑
- If programming, it would be written as !(X & Y) or similar.

- For multi-input NAND gates, outputs 0 if all inputs are 1.

Input | 00 | 01 | 10 | 11 |

Output | 1 | 1 | 1 | 0 |

**NOR**: Same as the OR operation, but the output is inverted. The other universal logic operation.- Usually written using ↓
- If programming, it would be written as !(X | Y) or similar.

- For multi-input NOR gates, outputs 0 if at least one input is 1.

Input | 00 | 01 | 10 | 11 |

Output | 1 | 0 | 0 | 0 |

**XNOR**: Same as the XOR, but the output is inverted.- 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. - For multi-input XNOR gates, outputs 1 if there are an even number of 1's.

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't have a certain input, which is either 00 or 11, depending on the type. If one of the inputs is a clock signal, a latch is 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 | (invalid) |

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