-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGate.php
More file actions
62 lines (56 loc) · 1.53 KB
/
Gate.php
File metadata and controls
62 lines (56 loc) · 1.53 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* Logic gates class containing the available logic gates
*/
class Gate
{
/**
* OR gate, returns true if one of the two inputs is true, else false
*/
static function or(bool $in0, bool $in1): bool
{
return $in0 || $in1;
}
/**
* NOR gate, returns true if both inputs are false, otherwise returns false
*/
static function nor(bool $in0, bool $in1): bool
{
return self::not(self::or($in0, $in1));
}
/**
* AND gate, returns true if both inputs are true, otherwise returns false
*/
static function and(bool $in0, bool $in1): bool
{
return $in0 && $in1;
}
/**
* NAND gate, returns false if both inputs are true, otherwise returns true
*/
static function nand(bool $in0, bool $in1): bool
{
return self::not(self::and($in0, $in1));
}
/**
* XOR gate, returns true if one of the two inputs is true, if both are true or none are true it will return false
*/
static function xor(bool $in0, bool $in1): bool
{
return self::and(self::or($in0, $in1), self::nand($in0, $in1));
}
/**
* XNOR gate, returns false if one of the two inputs is true, if both are true or none are true it will return true
*/
static function xnor(bool $in0, bool $in1): bool
{
return self::not(self::xor($in0, $in1));
}
/**
* NOT gate, if input is true it will return false and visa versa
*/
static function not(bool $in): bool
{
return !$in;
}
}