Class: Circuits::Component::HalfAdder

Inherits:
Base
  • Object
show all
Defined in:
lib/circuits/component/half_adder.rb

Overview

Half 1-bit Adder

Instance Attribute Summary

Attributes inherited from Base

#inputs, #outputs

Instance Method Summary collapse

Methods inherited from Base

#[], #tick, #tock

Constructor Details

#initializeHalfAdder

Returns a new instance of HalfAdder.



9
10
11
12
13
14
15
16
17
18
# File 'lib/circuits/component/half_adder.rb', line 9

def initialize
  and_gate = And.new
  xor_gate = Xor.new
  super(inputs: 2,
        outputs: [:s, :c_out],
        sub_components: [and_gate, xor_gate],
        ticks: 1)
  link_internals and_gate, xor_gate
  link_outputs and_gate, xor_gate
end