logicuit 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/logicuit/circuits/combinational/multiplexer4to1.rb +51 -0
- data/lib/logicuit/gates/nand.rb +27 -0
- data/lib/logicuit/gates/xor.rb +27 -0
- data/lib/logicuit/version.rb +1 -1
- data/lib/logicuit.rb +3 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39f6a3f233ed3a159f05332a47d1d882051ad7e9e2102f51c3375883fe366755
|
4
|
+
data.tar.gz: ef51eb6f22d2b3f4e0f0073c16644ec9f8ee3e798626826f7abde59399714363
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bfd774f4cadd41f070ec5c6cff8d2116775dfe6812ffd070c54478266756945b78426a2e89f3bea176008619930bc46387533a43376bc40a0c5f6ae49ac753c
|
7
|
+
data.tar.gz: 743a5e0ec704913583b98191320e1acde0d0332f8953f09ab88def5e8c162d5cd5130985e61f194c9fca295520816ffc024931f52ae859d6f2732278a67a6ac2
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Logicuit
|
4
|
+
module Circuits
|
5
|
+
module Combinational
|
6
|
+
# A Multiplexer with 4 inputs and 1 output
|
7
|
+
class Multiplexer4To1 < Base
|
8
|
+
define_inputs :c0, :c1, :c2, :c3, :b, :a
|
9
|
+
|
10
|
+
define_outputs y: lambda { |c0, c1, c2, c3, b, a|
|
11
|
+
(c0 && !b && !a) || (c1 && !b && a) || (c2 && b && !a) || (c3 && b && a)
|
12
|
+
}
|
13
|
+
|
14
|
+
diagram <<~DIAGRAM
|
15
|
+
(C0)---------------|
|
16
|
+
+---|AND|---+
|
17
|
+
| +-| |
|
18
|
+
| | |
|
19
|
+
(C1)---------------| +-|
|
20
|
+
+---|AND|-+ |
|
21
|
+
+-----------| +---|
|
22
|
+
| | | |OR|--(Y)
|
23
|
+
(C2)---------------| +---|
|
24
|
+
+-------------|AND|-+ |
|
25
|
+
| | | +-| +-|
|
26
|
+
| | | | |
|
27
|
+
(C3)---------------| |
|
28
|
+
+-------------|AND|---+
|
29
|
+
| +-----------|
|
30
|
+
| | | |
|
31
|
+
(B)--+---|NOT|-+ |
|
32
|
+
| |
|
33
|
+
(A)----+-|NOT|---+
|
34
|
+
DIAGRAM
|
35
|
+
|
36
|
+
truth_table <<~TRUTH_TABLE
|
37
|
+
| B | A | C0 | C1 | C2 | C3 | Y |
|
38
|
+
| - | - | -- | -- | -- | -- | - |
|
39
|
+
| 0 | 0 | 0 | x | x | x | 0 |
|
40
|
+
| 0 | 0 | 1 | x | x | x | 1 |
|
41
|
+
| 0 | 1 | x | 0 | x | x | 0 |
|
42
|
+
| 0 | 1 | x | 1 | x | x | 1 |
|
43
|
+
| 1 | 0 | x | x | 0 | x | 0 |
|
44
|
+
| 1 | 0 | x | x | 1 | x | 1 |
|
45
|
+
| 1 | 1 | x | x | x | 0 | 0 |
|
46
|
+
| 1 | 1 | x | x | x | 1 | 1 |
|
47
|
+
TRUTH_TABLE
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Logicuit
|
4
|
+
module Gates
|
5
|
+
# NAND gate
|
6
|
+
class Nand < Base
|
7
|
+
define_inputs :a, :b
|
8
|
+
|
9
|
+
define_outputs y: ->(a, b) { !(a && b) }
|
10
|
+
|
11
|
+
diagram <<~DIAGRAM
|
12
|
+
(A)-|
|
13
|
+
|NAND|-(Y)
|
14
|
+
(B)-|
|
15
|
+
DIAGRAM
|
16
|
+
|
17
|
+
truth_table <<~TRUTH_TABLE
|
18
|
+
| A | B | Y |
|
19
|
+
| - | - | - |
|
20
|
+
| 0 | 0 | 1 |
|
21
|
+
| 1 | 0 | 1 |
|
22
|
+
| 0 | 1 | 1 |
|
23
|
+
| 1 | 1 | 0 |
|
24
|
+
TRUTH_TABLE
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Logicuit
|
4
|
+
module Gates
|
5
|
+
# XOR gate
|
6
|
+
class Xor < Base
|
7
|
+
define_inputs :a, :b
|
8
|
+
|
9
|
+
define_outputs y: ->(a, b) { (a && !b) || (!a && b) }
|
10
|
+
|
11
|
+
diagram <<~DIAGRAM
|
12
|
+
(A)-|
|
13
|
+
|XOR|-(Y)
|
14
|
+
(B)-|
|
15
|
+
DIAGRAM
|
16
|
+
|
17
|
+
truth_table <<~TRUTH_TABLE
|
18
|
+
| A | B | Y |
|
19
|
+
| - | - | - |
|
20
|
+
| 0 | 0 | 0 |
|
21
|
+
| 1 | 0 | 1 |
|
22
|
+
| 0 | 1 | 1 |
|
23
|
+
| 1 | 1 | 0 |
|
24
|
+
TRUTH_TABLE
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/logicuit/version.rb
CHANGED
data/lib/logicuit.rb
CHANGED
@@ -5,8 +5,11 @@ require_relative "logicuit/base"
|
|
5
5
|
require_relative "logicuit/gates/and"
|
6
6
|
require_relative "logicuit/gates/or"
|
7
7
|
require_relative "logicuit/gates/not"
|
8
|
+
require_relative "logicuit/gates/nand"
|
9
|
+
require_relative "logicuit/gates/xor"
|
8
10
|
require_relative "logicuit/signals/signal"
|
9
11
|
require_relative "logicuit/signals/clock"
|
10
12
|
require_relative "logicuit/circuits/sequential/d_flip_flop"
|
11
13
|
require_relative "logicuit/circuits/combinational/multiplexer2to1"
|
14
|
+
require_relative "logicuit/circuits/combinational/multiplexer4to1"
|
12
15
|
require_relative "logicuit/circuits/system_level/one_bit_cpu"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logicuit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Koji NAKAMURA
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-03-
|
10
|
+
date: 2025-03-12 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
description: logi(c cir)cuit -> logicuit
|
13
13
|
email:
|
@@ -24,11 +24,14 @@ files:
|
|
24
24
|
- lib/logicuit/base.rb
|
25
25
|
- lib/logicuit/circuits/combinational/half_adder.rb
|
26
26
|
- lib/logicuit/circuits/combinational/multiplexer2to1.rb
|
27
|
+
- lib/logicuit/circuits/combinational/multiplexer4to1.rb
|
27
28
|
- lib/logicuit/circuits/sequential/d_flip_flop.rb
|
28
29
|
- lib/logicuit/circuits/system_level/one_bit_cpu.rb
|
29
30
|
- lib/logicuit/gates/and.rb
|
31
|
+
- lib/logicuit/gates/nand.rb
|
30
32
|
- lib/logicuit/gates/not.rb
|
31
33
|
- lib/logicuit/gates/or.rb
|
34
|
+
- lib/logicuit/gates/xor.rb
|
32
35
|
- lib/logicuit/signals/clock.rb
|
33
36
|
- lib/logicuit/signals/signal.rb
|
34
37
|
- lib/logicuit/version.rb
|