Originally posted by: NogginBoink
Aha! The homework problem (cascading two-input XOR gates) will give a 0 output if there are an even number of 0 inputs, and a 1 output if there are an odd number of 0 inputs.
To be technically correct, you should count the number of ones as odd or even as opposed to the zeros (XOR is odd parity). If you had a 9-input XOR, an even number of zeros would actually result in a 1 output. So, to be consistent, count the ones...
🙂
However that problem is distinctly different than logic that is 1 if an only if a single bit is 1. For instance, a bitwise XOR of 00100011 gives 1, whereas the above logic would give 0 since more than one input bit is 1.
EDIT:
I think one solution to the above problem is as follows
[((A xor B) xor (C xor D)) and ((A and B) nor (C and D))]
xor
[((E xor F) xor (G xor H)) and ((E and F) nor (G and H))]
Explanation:
"((A xor B) xor (C xor D))" is true when either one or three of the inputs is one.
"((A and B) nor (C and D))" is automatically false when three inputs are true, and automatically true when only one input is true (i.e. three are false).
ANDing the two together means the output is only true when one input is true.
Do this for the top and bottom four input bits. XOR the results. This ensures that the output is true if exclusively one bit is true among the top 4 or one bit is true among the bottom four.
Hence, this logic is one if and only if a single bit (among A-E) is one.
Yet another solution is to do
AB^C^D^E^F^G^H^+A^BC^D^E^F^G^H^... (where ^ is complement, or NOT of input) all the way through the sequence. however that would require many more logic gates.