def add_truth(inputs): ''' Split inputs into two and return sum that is half length. First is carry. For the output, last bit is carry ''' length = len(inputs) c = inputs[0] half = (length-1)/2 inputa = inputs[0:half] inputb = inputs[half:length] a = get_uint(inputa) b = get_uint(inputb) result = a+b return get_bools(result, half+1)
def decoder_truth(inputs): ''' convert inputs to a number. ''' number = get_uint(inputs) outputs = [False]*int(math.pow(2, len(inputs))) outputs[number] = True return outputs
def mux_truth(inputs): ''' inputs, then selects ''' number_selects = get_selects(len(inputs)) number_ins = len(inputs) - number_selects #print "num selects: {0}, inputs: {1}".format(number_selects,inputs) ins = inputs[0:number_ins] selects = inputs[number_ins:] select_index = get_uint(selects) #print "select: ", select_index return [ins[select_index]]