- 0 / 1 --- ++++++++++++
+ OPERATOR +--- 0 / 1
- 0 / 1 --- ++++++++++++
Boolean logic is collective name for the groups and operations done using operands that can only have the value of 0 (false) and 1 (true). The operators are gates. Gates are the closest we can get to electronics while still retaining the idea of programming, as they are designed similarly to real-life circuits and the statements they use are identical to those used in programming languages.
Boolean logic is possible thanks to transistors - switches which act as basic building blocks for digital electronic computers.
AND - the output is TRUE if both statements are TRUE a | b |out| ---|---|---| 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 1 | 1 |
OR - the output is TRUE if either statement is TRUE a | b |out| ===|===|===| 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 |
NOT - only takes one operand, the output is flipped (FALSE to TRUE, TRUE to FALSE) a |out| ===|===| 0 | 1 | 1 | 0 |
Any boolean manipulation is possible with these three gates. Actually just two - even OR can be constructed from them, the following set of operators has the exact same output as OR:
+++++ +++++++++++
- a ---+NOT+---+ +
+++++ + + +++++
+ AND +---+NOT+--- OUT
+++++ + + +++++
- b ---+NOT+---+ +
+++++ +++++++++++
There. Electric circuit for AND and OR:
/ / /
---o o---o o-- ----o o----
| | | |
| | | / |
| | |---o o---|
---B-------L---- | |
| |
---B---L----
NAND is the negation of AND. It is a functionally complete gate - any other gate can be implemented with it.
a | b |out| ===|===|===| 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 1 | 0 |
Implementation of NOT:
- a ---++++++++
+ NAND +--- OUT
- a ---++++++++
AND is simply a reverse of NAND, it can be applied by combining NAND and NOT.
- a ---++++++++ +++++++
+ NAND +---+ NOT +--- OUT
- b ---++++++++ +++++++
Composite operators - take in more than two boolean inputs - ex. multiadder:
- a ---+++++++ +++++++
+ AND +------+ +
- b ---+++++++ + AND +--- OUT
+ +
- c ----------------+++++++