# How do I use multiple BCD switches as a single binary input?

I'm trying to convert a 4-digit (decimal) number to binary. My input is a BCD switch (this one). I've been looking to see if I can find either a logic-based circuit or a specific decoder IC to convert the values off of the switch array into a single binary number. I don't seem to be having much luck though. Is there a good way to do this wither with some sort of converter or with logic? I'd appreciate your thoughts. Thanks!

• Way? Yes. Good way? No. Time to learn about PLDs or MCUs. Nov 16, 2013 at 16:53
• Why can't you use the 16 bit result directly from the switch? What is the actual problem you are trying to solve? Nov 16, 2013 at 17:27
• Let's say I use the switches to enter 24. I get two 4-bit outputs: 0010 0100. I would like to convert that into one binary number, 00011000. Is that more clear? Nov 16, 2013 at 17:29
• No. That's exactly what you asked in your question. Nov 16, 2013 at 17:32
• My point was that the switch does not output normal 16-bit binary. It outputs four 4-bit binary digits, which I would like to combine into one 16-bit number. Nov 16, 2013 at 17:53

As you're very unlikely to find an off the shelf chip that solves a specific (but not very common) problem the chances are you will have to build something. The conversion of the BCD to binary is a simple but repetitive task and is suited to a small micro controller but the number of input/output pins required is quite large so converting the code to a serial stream with an external shift register - parallel in/serial out for reading the BCD switches and a serial in/parallel out for the output binary number will help out. You should be able to control everything with no more than 6 i/o pins on the controller (fix operation mode with a pull up/down resistor)

You'll need 14 bits to display the maximum value of the bcd (9999). The uC can just about be anything. Input through 74F676 16-Bit Serial/Parallel-In, Serial-Out Shift Register and output through 74F675A 16-Bit Serial-In, Serial/Parallel-Out Shift Register

Expanding the number of BCD switches involves adding extra shift registers and a small change in the program.

• Thanks for your reply. That makes sense to me, and although I was really hoping to avoid the use of a microcontroller in the project, it's starting to look like the only viable option. Thanks! Nov 16, 2013 at 18:16

You can do it with logic chips, but it's not going to be fun. If the digits are A, B, C, and D, you would need to calculate A + 10*B + 100*C + 1000*D. This can be expanded to A + 2*B + 8*B + 4*C + 32*C + 64*C + 8*D + 32*D + 64*D + 128*D + 256*D + 512*D. Power of 2 constant multiples are just bit shifts, so all you need is a whole bunch of adders. Or a CPLD/FPGA/uC/etc.

Performing the conversion using off-the-shelf discrete logic would be possible, but would probably require somewhere between 6 and 12 chips. One could also easily use a pair of 32Kx8 ROM chips (or a 32Kx16), observing that the LSB of the input value doesn't participate in the result; the only advantage of that over a microcontroller is that its output would represent the switch values in "real time" with no clocking needed. It would also be possible to use some form of programmable logic, though I think any space-efficient solution would have to be sequential, implying that one might as well use a microcontroller.

If one wants to implement a design using off-the-shelf components, it might be easiest to build a circuit based upon a BCD counter, a binary counter, a couple of 8-bit comparators, 8-bit latches, and some glue logic. Basically, count from 0000 to 9999 (BCD) repeatedly; when the count wraps, reset the binary counter, and when the BCD count matches the switch input latch the binary counter value. Other sequential approaches may be faster, but the aforementioned approach should be simple. An alternative would be to some a latches, multiplexers, and ALU so that the circuit iteratively multiples an accumulator by 10 and adds the next switch input. That approach could probably produce a new output every 8 cycles or so, but I don't think there's likely a real need for anything that fast.