In [1]:
# Imports
from __future__ import print_function
from BinPy.combinational.combinational import *
In [2]:
print(HalfAdder.__doc__)
In [3]:
# Initializing the HalfAdder
# Input is of the form (bit_1, bit_2)
ha = HalfAdder(1, 1)
# Output of HalfAdder
# Output is of the form [ CARRY, SUM ]
print (ha.output())
In [4]:
# Input changes ( index, value )
ha.set_input(1, 0)
# New Output of the BinaryAdder
print (ha.output())
In [5]:
# Using Connectors as the input lines
# Take a Connector
conn_1 = Connector(1)
conn_2 = Connector(0)
conn_3 = Connector()
# Setting the input of the Half Adder to the Connector conn_1 and conn_2
ha.set_inputs(conn_1, conn_2)
# Set Carry Output of Binary Adder to Connector conn_3
ha.set_output(0, conn_3)
# Use this connector as the input to gate1
gate1 = NOT(conn_3)
# Output of the gate1
print (gate1.output())
In [6]:
# Change the value of the conn_2
conn_2.set_logic(0)
# Verify with the output of the HalfAdder
print (ha.output())
In [7]:
print(FullAdder.__doc__)
In [8]:
a, b, ci, s, co = Connector(1), Connector(1), Connector(1), Connector(), Connector()
# Initializing full adder using connectors
fa = FullAdder(a, b, ci)
# Connect outputs
fa.set_output(0, co)
fa.set_output(1, s)
In [9]:
print (co.get_logic(), s.get_logic())