How can I select a single bit out of an array of latches?
Sebastian Wright
Let's say I have 4 latches, each representing a bit:
I want to be able to see the value stored at a specific bit. I specify which bit I want to look at by entering a binary number via. switches:
So if I were to enter (0, 0), it would output the value stored at the leftmost bit. If I were to enter (0, 1), it would output the value stored at the bit 2nd to the left, and so on, up to (1, 1), which would output the rightmost bit.
How would I do this? Could you point me to a tutorial or answer yourself? I have been looking for a week now, but I have not really been sure what I should search.
Also, I understand that Arqade might not be the best place to ask this question. If you feel that way could you please suggest a better place to ask? Thank you!
PS. To those of you who understand programming, think of it as I would like to do this:
output = latches[input];
1 Answer
What you want is a multiplexer or mux. A multiplexer allows you to select from multiple inputs (your latches) using a smaller number of control bits. I have built a quick multiplexer myself since all the tutorials I found on Youtube were long and confusing.This is my 4x2 mux. The red box indicates a simulation of your latches.
To begin, we need to interface your latches with the beginning of the multiplexer.
1. Connect the outputs of your latches to the circled terminals.
Next, we look at the multiplexers. There are technically three 2x1 muxes configures to create a 4x2 mux. What you just connected your latches to were the first two muxes.
2. Build the first two muxes. In front of the redstone torches from step 1, there are repeaters pointing towards the green block. The pistons will select which latch signal is passed through. Now we have two signals to deal with instead of 4. Connect the pistons as shown. This will mean our signals are either 0 and 2, or 1 and 3.
3. Jump over the redstone. This is just a quick and dirty way to get the two signals where we need them.
4. Build the third mux. This should look similar to the first two. Moving to the end.
5. Build the output and control station. The blue wire controls the third mux, the yellow controls the first two, and the red is your output.
Remember, a lever is a 1 when it is down. If you number your latches from left to right as [L3|L2|L1|L0], you will get this table