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.
npm install @hckrnews/logic-gates
or
yarn add @hckrnews/logic-gates
npm run test
or
yarn test
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:
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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] |