# How can I select a single bit out of an array of latches?

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];

-
This is seriously much more in line with electrical engineering/digital circuit design than it is with Minecraft gameplay. – StrixVaria Feb 4 '13 at 22:56
@StrixVaria That's what I meant when I said that this question isn't that appropriate for Arqade... – Aaron Feb 4 '13 at 23:31
@JesusPlusPlus: I think he meant it would be more on-topic at s.tk/ee, but it's fine here too, especially with OrigamiRob's answer. – Ullallulloo Feb 5 '13 at 0:24
@StrixVaria The underlying theory is appropriate for EE, but we are the people who know how to build things in Minecraft. – user9983 Feb 5 '13 at 0:41

## 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

-
Keep in mind, this is just a quick and dirty design. I'm sure there are more optimal versions, but this should illustrate the basic principle and let you make improvements. – user9983 Feb 5 '13 at 0:29
@JesusPlusPlus I am an Electrical Engineer. I knew you needed a mux, but I had never built one in MC. I looked up some tutorials and they all looked bad, so I made one off the top of my head. It's quite funny how you independently invented the exact concept of a mux. Fun fact, you can do the opposite with a demultiplexer. – user9983 Feb 5 '13 at 1:38
That's really cool, the entire reason I'm learning redstone in Minecraft is because I'm looking at being an Electrical Engineer as a job when I grow up (or at least as a hobby). – Aaron Feb 5 '13 at 1:40
@JesusPlusPlus Good luck! Electrical Engineering is a pretty broad field. Digital circuits are only a tiny part of it. – user9983 Feb 5 '13 at 1:45
@JesusPlusPlus That's awesome! Redstone is actually really useful for this, because it gives you a graphical, interactive way to see how circuits work. I took an EE class in college, and spent quite a bit of time building the circuits we talked about. – SaintWacko Feb 5 '13 at 2:18