-
Notifications
You must be signed in to change notification settings - Fork 11
/
And.js
46 lines (39 loc) · 835 Bytes
/
And.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* The MIT License (MIT)
* Copyright (c) 2017-present Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
*/
'use strict';
const BuiltInGate = require('../BuiltInGate');
/**
* Canonical truth table for the `And` gate.
*/
const TRUTH_TABLE = [
{a: 0, b: 0, out: 0},
{a: 0, b: 1, out: 0},
{a: 1, b: 0, out: 0},
{a: 1, b: 1, out: 1},
];
/**
* A bitwise 1-bit And gate.
*/
class And extends BuiltInGate {
/**
* a & b
*/
eval() {
const a = this.getInputPins()[0].getValue();
const b = this.getInputPins()[1].getValue();
this.getOutputPins()[0].setValue(a & b);
}
}
/**
* Specification of the `And` gate.
*/
And.Spec = {
name: 'And',
description: 'Implements bitwise 1-bit And & operation.',
inputPins: ['a', 'b'],
outputPins: ['out'],
truthTable: TRUTH_TABLE,
};
module.exports = And;