Difference between revisions of "CSC270 Homework 4 Solution 2011"
Line 32: | Line 32: | ||
return inputs[ C0 + 2*C1 ] | return inputs[ C0 + 2*C1 ] | ||
− | def decode3To8( | + | def decode3To8( I2, I1, I0 ): |
outputs = [0, 0, 0, 0, 0, 0, 0, 0] | outputs = [0, 0, 0, 0, 0, 0, 0, 0] | ||
outputs[ I0 + I1*2 + I2*4 ] = 1 | outputs[ I0 + I1*2 + I2*4 ] = 1 | ||
Line 39: | Line 39: | ||
def main(): | def main(): | ||
#--- verification of the majority voter --- | #--- verification of the majority voter --- | ||
+ | print "Majority voter verification" | ||
print "a b c | f " | print "a b c | f " | ||
print "------+---" | print "------+---" | ||
Line 46: | Line 47: | ||
f = mux4To1( 0, c, c, 1, a, b ) | f = mux4To1( 0, c, c, 1, a, b ) | ||
print "%d %d %d | %d" % ( a, b, c, f ) | print "%d %d %d | %d" % ( a, b, c, f ) | ||
+ | |||
+ | #--- verification of decoder --- | ||
+ | print "\n\nDecoder verification" | ||
+ | print "a b c | I7 I6 I5 I4 I3 I2 I1 I0" | ||
+ | print "------+------------------------" | ||
+ | for a in [0,1]: | ||
+ | for b in [0,1]: | ||
+ | for c in [0,1]: | ||
+ | I7, I6, I5, I4, I3, I2, I1, I0 = decode3To8( a, b, c ) | ||
+ | print "%d %d %d | %2d %2d %2d %2d %2d %2d %2d %2d" \ | ||
+ | % (a, b, c, I7, I6, I5, I4, I3, I2, I1, I0 ) | ||
main() | main() | ||
+ | |||
</pre></code> | </pre></code> | ||
==Output== | ==Output== | ||
<code><pre> | <code><pre> | ||
+ | Majority voter verification | ||
a b c | f | a b c | f | ||
------+--- | ------+--- | ||
Line 63: | Line 77: | ||
1 1 0 | 1 | 1 1 0 | 1 | ||
1 1 1 | 1 | 1 1 1 | 1 | ||
+ | |||
+ | |||
+ | Decoder verification | ||
+ | a b c | I7 I6 I5 I4 I3 I2 I1 I0 | ||
+ | ------+------------------------ | ||
+ | 0 0 0 | 1 0 0 0 0 0 0 0 | ||
+ | 0 0 1 | 0 1 0 0 0 0 0 0 | ||
+ | 0 1 0 | 0 0 1 0 0 0 0 0 | ||
+ | 0 1 1 | 0 0 0 1 0 0 0 0 | ||
+ | 1 0 0 | 0 0 0 0 1 0 0 0 | ||
+ | 1 0 1 | 0 0 0 0 0 1 0 0 | ||
+ | 1 1 0 | 0 0 0 0 0 0 1 0 | ||
+ | 1 1 1 | 0 0 0 0 0 0 0 1 | ||
</pre></code> | </pre></code> |