@hckrnews/logic-gates
v2.0.4
Published
Generate logic gates without thinking.
Downloads
17
Readme
Logic gates package
Generate logic gates without thinking. You can use this package if you need well tested logic gate checks. e.g. if all options must be true or false, but don't must be a mix of true and false, you can use the xand gate.
Installation
npm install @hckrnews/logic-gates
or
yarn add @hckrnews/logic-gates
Test the package
npm run test
or
yarn test
Usage
Example usage:
import { AndGate } from "@hckrnews/logic-gates";
const gate = AndGate.create([true, true]);
Send an array with boolean's to the create method.
Get the gate result:
gate.output
Output a boolean:
true
Or use the short syntax:
import { and } from "@hckrnews/logic-gates";
and([true, true])
Output a boolean:
true
All options:
Short syntax:
And gate
| Input 1 | Input 2 | Input 3 | Output | | ------- | ------- | ------- | ------ | | 0 | 0 | 0 | 0 | | 0 | 0 | 1 | 0 | | 0 | 1 | 0 | 0 | | 0 | 1 | 1 | 0 | | 1 | 0 | 0 | 0 | | 1 | 0 | 1 | 0 | | 1 | 1 | 0 | 0 | | 1 | 1 | 1 | 1 |
Nand gate
| Input 1 | Input 2 | Input 3 | Output | | ------- | ------- | ------- | ------ | | 0 | 0 | 0 | 1 | | 0 | 0 | 1 | 1 | | 0 | 1 | 0 | 1 | | 0 | 1 | 1 | 1 | | 1 | 0 | 0 | 1 | | 1 | 0 | 1 | 1 | | 1 | 1 | 0 | 1 | | 1 | 1 | 1 | 0 |
Or gate
| Input 1 | Input 2 | Input 3 | Output | | ------- | ------- | ------- | ------ | | 0 | 0 | 0 | 0 | | 0 | 0 | 1 | 1 | | 0 | 1 | 0 | 1 | | 0 | 1 | 1 | 1 | | 1 | 0 | 0 | 1 | | 1 | 0 | 1 | 1 | | 1 | 1 | 0 | 1 | | 1 | 1 | 1 | 1 |
Nor gate
| Input 1 | Input 2 | Input 3 | Output | | ------- | ------- | ------- | ------ | | 0 | 0 | 0 | 1 | | 0 | 0 | 1 | 0 | | 0 | 1 | 0 | 0 | | 0 | 1 | 1 | 0 | | 1 | 0 | 0 | 0 | | 1 | 0 | 1 | 0 | | 1 | 1 | 0 | 0 | | 1 | 1 | 1 | 0 |
Xor gate
| Input 1 | Input 2 | Input 3 | Output | | ------- | ------- | ------- | ------ | | 0 | 0 | 0 | 0 | | 0 | 0 | 1 | 1 | | 0 | 1 | 0 | 1 | | 0 | 1 | 1 | 0 | | 1 | 0 | 0 | 1 | | 1 | 0 | 1 | 0 | | 1 | 1 | 0 | 0 | | 1 | 1 | 1 | 1 |
Xnor gate
| Input 1 | Input 2 | Input 3 | Output | | ------- | ------- | ------- | ------ | | 0 | 0 | 0 | 1 | | 0 | 0 | 1 | 0 | | 0 | 1 | 0 | 0 | | 0 | 1 | 1 | 1 | | 1 | 0 | 0 | 0 | | 1 | 0 | 1 | 1 | | 1 | 1 | 0 | 1 | | 1 | 1 | 1 | 0 |
Xand gate
| Input 1 | Input 2 | Input 3 | Output | | ------- | ------- | ------- | ------ | | 0 | 0 | 0 | 1 | | 0 | 0 | 1 | 0 | | 0 | 1 | 0 | 0 | | 0 | 1 | 1 | 0 | | 1 | 0 | 0 | 0 | | 1 | 0 | 1 | 0 | | 1 | 1 | 0 | 0 | | 1 | 1 | 1 | 1 |
Xnand gate
| Input 1 | Input 2 | Input 3 | Output | | ------- | ------- | ------- | ------ | | 0 | 0 | 0 | 0 | | 0 | 0 | 1 | 1 | | 0 | 1 | 0 | 1 | | 0 | 1 | 1 | 1 | | 1 | 0 | 0 | 1 | | 1 | 0 | 1 | 1 | | 1 | 1 | 0 | 1 | | 1 | 1 | 1 | 0 |
Not gate
| Input 1 | Input 2 | Input 3 | Output | | ------- | ------- | ------- | ------- | | 0 | 0 | 0 | [1,1,1] | | 0 | 0 | 1 | [1,1,0] | | 0 | 1 | 0 | [1,0,1] | | 0 | 1 | 1 | [1,0,0] | | 1 | 0 | 0 | [0,1,1] | | 1 | 0 | 1 | [0,1,0] | | 1 | 1 | 0 | [0,0,1] | | 1 | 1 | 1 | [0,0,0] |