В настоящее время я делаю проект в моем классе дискретной математики, и мы должны код:Pipon Ripple carry Adder?
1.) RippleCarryAdder: это схема для добавления фиксированного размера, 5-битовые целые числа. Параметры:
x_array: operand 1, i.e. an array of 5 wires
y_array: operand 2, i.e. an array of 5 wires
s_array: sum, i.e. an array of 6 wires
2.) RippleCarryAdder: это схема для добавления п-битовых чисел. Параметры:
x_array: operand 1, i.e. an array of n wires
y_array: operand 2, i.e. an array of n wires
s_array: sum, i.e. an array of (n+1) wires
Я уже закодированы половину и полный сумматор.
Я понимаю основную концепцию Ripple Carry. Мне просто сложно сбрасывать код. Любая помощь будет оценена!
Код:
#!/usr/bin/python3
import unittest
from digital_circuit_core import *
class InputLengthException(Exception): pass
class MyPrettySimulator(Simulator):
def HalfAdder(self, a, b, s, c):
# internal wires
d = self.Wire('d-wire')
e = self.Wire('e-wire')
self.OrGate(a, b, d)
self.AndGate(a, b, c)
self.Inverter(c, e)
self.AndGate(d, e, s)
return 'ok'
def FullAdder(self, a, b, c_in, s, c_out):
# internal wires
d = self.Wire()
c1 = self.Wire()
c2 = self.Wire()
self.HalfAdder(b, c_in, d, c1)
self.HalfAdder(a, d, s, c2)
self.OrGate(c1, c2, c_out)
return 'ok'
def RippleCarryAdder_5_bits(self, x_array, y_array, s_array):
############# YOUR CODE HERE ###############
return 'ok'
def RippleCarryAdder(self, x_arr, y_arr, s_arr):
############ YOUR CODE HERE ############
return 'ok'