Difference between revisions of "CSC270 Homework 4 Solution 2011"

From dftwiki3
Jump to: navigation, search
Line 20: Line 20:
 
<br />
 
<br />
 
<br />
 
<br />
For the last diagram, the design is correct, but could have been simplified
+
For the last diagram, the design is correct, but could have been simplified by setting the d input to 0 and leaving I8 to I15 unconnected (we use the symbol NC in diagrams to indicate the fact that an input or output is "not connected" to anything.
 +
 
 +
==Code==
 +
<code><pre>
 +
# solution program for hw4                                                                                                                                     
 +
# D. Thiebaut                                                                                                                                                 
 +
#                                                                                                                                                             
 +
def mux4To1( I0, I1, I2, I3, C0, C1 ):
 +
    inputs = ( I0, I1, I2, I3 )
 +
    return inputs[ C0 + 2*C1 ]
 +
 
 +
def decode3To8( I0, I1, I2 ):
 +
    outputs = [0, 0, 0, 0, 0, 0, 0, 0]
 +
    outputs[ I0 + I1*2 + I2*4 ] = 1
 +
    return outputs
 +
 
 +
def main():
 +
    #--- verification of the majority voter ---                                                                                                               
 +
    print "a b c | f "
 +
    print "------+---"
 +
    for a in [0,1]:
 +
        for b in [0,1]:
 +
            for c in [0,1]:
 +
                f = mux4To1( 0, c, c, 1, a, b )
 +
                print "%d %d %d | %d" % ( a, b, c, f )
 +
 
 +
 
 +
main()
 +
 
 +
 
 +
 
 +
 
 +
 
 +
</pre></code>
 +
 
 
=Extra Credit=
 
=Extra Credit=
  

Revision as of 12:08, 1 March 2011

--D. Thiebaut 10:44, 1 March 2011 (EST)



...