Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

To Do: use the Mux_2to1, implement a 4 to 1 multiplexer class Mux_4to1 give 4 in

ID: 3683786 • Letter: T

Question

 To Do: use the Mux_2to1, implement a 4 to 1 multiplexer class Mux_4to1 
 give 4 inputs to your mux_4to1, and 2 control signal also 
  THE FOLLOWING CODE BELOW IS IN RUBY: 
  class Circuit    # constructor method    def initialize(in1, in2)       @in1, @in2 = in1, in2    end end  class AndGate < Circuit        def cir_func()       (@in1 && @in2)    end end  class OrGate < Circuit        def cir_func()       (@in1 || @in2)    end end  class NotGate < Circuit    def initialize(in1)       @in1 = in1    end       def cir_func()       (not @in1)    end end  class Mux_2to1 < Circuit      def initialize(in1, in2, ctr1)         @in1_ = in1         @in2_ = in2         @ctr1_ = ctr1     end     def cir_func()       inv_ctr = NotGate.new(@ctr1_).cir_func()       a0 = AndGate.new(@in1_, inv_ctr).cir_func()       a1 = AndGate.new(@in2_, @ctr1_).cir_func()       o0 = OrGate.new(a0, a1)       return o0.cir_func()     end end   #---------------------------------------------------------------  #use the Mux_2to1, implement a 4 to 1 multiplexer class Mux_4to1   def Boolean(string)   return true if string== true || string =~ (/(true|1)$/i)   return false if string== false || string.nil? || string =~ (/(false|0)$/i)   raise ArgumentError.new("invalid value for Boolean: "#{string}"") end   puts "Please enter the first input: " input1 = gets()  puts "Please enter the second input: " input2 = gets()  puts "Please enter the third input: " input3 = gets()  puts "Please enter the fourth input: " input4 = gets()  puts "Please enter the control signal 0: " ctrsig0 = gets()  puts "Please enter the control signal 1: " ctrsig1 = gets()  #--------------------------------------------------------------- # class demo  # woodyMux = Mux_2to1.new(Boolean(input1), Boolean(input2), Boolean(ctrsig)) # # outputofwoodyMux = woodyMux.cir_func() # # puts "the result of the woodyMux is : #{outputofwoodyMux}"     #---------------------------------------------------------------   ## give 4 inputs to your mux_4to1, and 2 control signal also # Please enter the first input: # 0 # Please enter the second input: # 1 # Please enter the third input: # 0 # Please enter the fourth input: # 1 # Please enter the control signal 0: # 0 # Please enter the control signal 1: # 1 # the result of the woodyMux is : true ## Please note in the ctr signal 1 is going to be used as the control signal of two 2to1mux, ctr signal 0 is going to be used as the control signal for only 1 2to1mux 

Explanation / Answer


class circuit(object):
   def __init__(self, in1, in2):
       self.in1_ = in1
       self.in2_ = in2
  
class andgate(circuit):
   def cir_func(self):
       return self.in1_ and self.in2_
  
class andgate_3in(circuit):
  
   def __init__(self, in1, in2, in3):
       self.in1_ = in1
       self.in2_ = in2
       self.in3_ = in3
  
   def cir_func(self):
       return self.in1_ and self.in2_ and self.in3_

class orgate(circuit):
   def cir_func(self):
       return self.in1_ or self.in2_

      
class notgate(circuit):

   def __init__(self, in1):
       self.in1_ = in1

   def cir_func(self):
       return not self.in1_
      
      
class mux_2to1(circuit):
   def __init__(self, in1, in2, ctr1):  
       self.in1_ = in1
       self.in2_ = in2
       self.ctr1_ = ctr1
      
   def cir_func(self):
      
       inv_ctr = notgate(self.ctr1_).cir_func()
      
       a0 = andgate(self.in1_, inv_ctr).cir_func()
       a1 = andgate(self.in2_, self.ctr1_).cir_func()
      
       o0 = orgate(a0, a1)
      
       return o0.cir_func()
          
  

#---------------------------------------------------------------
# homework 6 due Tu 11/17/15 5:45pm

'''
use the mux_2to1, implement a 4 to 1 multiplexer class mux_4to1
'''
      
def main():

   input1_b = [None]*32
   input2_b = [None]*32
   input3_b = [None]*32
   input4_b = [None]*32
  
   ctr_b = [None]*32
  
   input1 = raw_input("Please Enter the first input: ")
   input2 = raw_input("Please Enter the second input: ")
   input3 = raw_input("Please Enter the third input: ")
   input4 = raw_input("Please Enter the fouth input: ")
   ctr = raw_input("Please Enter the ctr signal input: ")
  
  
   for i in range(0, len(input1)):
      >        if (one_or_zero == '1'):
           input1_b[i] = True
       else:
           input1_b[i] = False

   for i in range(0, len(input2)):
      >        if (one_or_zero == '1'):
           input2_b[i] = True
       else:
           input2_b[i] = False  
  
   for i in range(0, len(input3)):
      >        if (one_or_zero == '1'):
           input3_b[i] = True
       else:
           input3_b[i] = False  
  
   for i in range(0, len(ctr)):
      >        if (one_or_zero == '1'):
           ctr_b[i] = True
       else:
           ctr_b[i] = False  
  
   for i in range(0, len(input4)):
      >        if (one_or_zero == '1'):
           input4_b[i] = True
       else:
           input4_b[i] = False
  
   o_mux = mux_2to1(input1_b[0], input2_b[0], ctr_b[0])
   i_mux = mux_2to1(input3_b[0], input4_b[0], ctr_b[0])
   output = o_mux.cir_func()
   output1 = i_mux.cir_func()
   if(output == False):
       output = 1
   else:
       output = 0
          
  
   #---------------------------------------------------------------

   '''
   give 4 inputs to your mux_4to1, and 2-bit control signal also
  
   e.g inputs
   Please Enter the first input: 1
   Please Enter the second input: 1
   Please Enter the third input: 0
   Please Enter the fouth input: 1
   Please Enter the ctr signal input: 01
  
   your output should be:
   the output for mux_4to1: False
      
   Please note in the ctr signal 01, 0 is going to be used as the control signal of two 2to1mux, 1 is going to be used as the control signal for only 1 2to1mux
  
   '''
      
   print "the output for woodyMux: ", output
  
if __name__ == '__main__':
   main()# your code goes here

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote