Skip to content

NandGate

Jaime Redondo edited this page Jan 3, 2021 · 2 revisions

NandGate

Class for the NAND gate.

Hierarchy

  • BaseGate

    NandGate

Constructor

new NandGate(input: Input): NandGate

Parameters

Name Type Default Description
input Input none The gate's input.

Returns

NandGate - The gate object.

Properties

input

The gate's input.
Type: Input


output

The gate's output.
Type: Output


truthTable

The gate's truth table.
Type: TruthTable

Methods

static create(input: Input): BaseGate

Create an instance of the gate.

Parameters

Name Type Default Description
input Input none The gate's input.

Returns

BaseGate - The gate object.


static getTruthTable(inputs?: number = 2): TruthTable

Get the gate's truth table for the specified number of inputs.

Parameters

Name Type Default Description
inputs number 2 The number of inputs for the truth table.

Returns

TruthTable - The truth table.

Example

const { NandGate } = require("@jaimermxd/logic-gates");

var gate = NandGate.create([false, true]);

console.log(gate.input); // [ false, true ]
console.log(gate.output); // true
console.log(gate.truthTable);

/*
[
  [ false, false, true ],
  [ false, true, true ],
  [ true, false, true ],
  [ true, true, false ]
]
*/

var table = NandGate.getTruthTable(3);

console.log(table);

/*
[
  [ false, false, false, true ],
  [ false, false, true, true ],
  [ false, true, false, true ],
  [ false, true, true, true ],
  [ true, false, false, true ],
  [ true, false, true, true ],
  [ true, true, false, true ],
  [ true, true, true, false ]
]
*/

Clone this wiki locally