Logical Gates
A simple (zero-dependencies) library to implement logic gates in JavaScript/TypeScript.
Installation
Using NPM:
npm install logical-gates-ts
Using Yarn:
yarn add logical-gates-ts
Using pnpm:
pnpm add logical-gates-ts
How it works
This section provide the mathematical/logical description scheme for each logic gate
AND
INPUT | OUTPUT | |
---|---|---|
0 | 0 | 0 |
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 1 |
Example:
import { LogicalGates } from 'logical-gates-ts'
LogicalGates.AND(true, false) // -> false
OR
INPUT | OUTPUT | |
---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 1 |
Example:
import { LogicalGates } from 'logical-gates-ts'
LogicalGates.OR(true, false) // -> true
XOR
INPUT | OUTPUT | |
---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
Example:
import { LogicalGates } from 'logical-gates-ts'
LogicalGates.XOR(true, false) // -> true
NAND
INPUT | OUTPUT | |
---|---|---|
0 | 0 | 1 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
Example:
import { LogicalGates } from 'logical-gates-ts'
LogicalGates.NAND(true, false) // -> true
NOR
INPUT | OUTPUT | |
---|---|---|
0 | 0 | 1 |
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 0 |
Example:
import { LogicalGates } from 'logical-gates-ts'
LogicalGates.NOR(true, false) // -> false
XNOR
INPUT | OUTPUT | |
---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
Example:
import { LogicalGates } from 'logical-gates-ts'
LogicalGates.XNOR(true, false) // -> true