In PYTHON write short individual demo codes for each of the

In PYTHON, write short individual demo codes for each of the following logic components:

1. Half Adder

2. Full Adder

(2 separate codes - one for half adder, other for full adder. Keep them short)

Please provide a picture of your code and your output.

Solution

Following is the optimized code for full and half adders in python-

For half adder-

def Xor(self, a,b, xor):

    pa = self.Wire(\'pa\')

    pb = self.Wire(\'pb\')

    self.Inverter(a,pa)

    self.Inverter(a,pb)

    a1 = self.Wire(\'a1\')

    a2 = self.Wire(\'a2\')

    self.AndGate(pa,b,a1)

    self.AndGate(a,pb,a2)

    self.OrGate(a1,a2,xor)

    pass

def HalfAdder(self, a, b, s, c):

    self.AndGate(a,b,c)

    self.Xor(a,b,s)

For half adder-

def FullAdder(self,p,q,c_i,s, c_out):

    ha1s = self.Wire(\'ha1s\')

    ha1c = self.Wire(\'ha1c\')

    self.HalfAdder(p,q,ha1s,ha1c)

    ha2c = self.Wire(\'ha2c\')

    self.HalfAdder(ha1s,c_i,s,ha2c)

    self.OrGate(ha1c,ha2c,c_out)

    pass

In PYTHON, write short individual demo codes for each of the following logic components: 1. Half Adder 2. Full Adder (2 separate codes - one for half adder, oth

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site