Electrical – How to convert a number to its 4-bit binary equivalent using logic gates

7segmentdisplaybinarydigital-logiclogic-gateslogisim

Circuit storing number as binary
Keypad[![Storing the number as binary]2

My aim is to store numbers from 0-15(4 bits) as binary. The numbers are inputted using a keypad with buttons labelled N0-N9.
The circuit works for single digit numbers(0-9). But I don't know how to make it work for numbers 10-15.
I also want to use two 7-segment displays to display the numbers inputted from the keypad. Initially, the display shows "00". If a single-digit number like 4 has to be inputted, the display reads "04". If a two-digit number like 13 has to be inputted, the display first reads "01" when 1 is pressed and then "13" when 3 is pressed. If a number greater than 15 is inputted(overflow), "NA" or something should be displayed.

Best Answer

Use 2 74LS148 or 2 74HC148 priority encoders, which drive a quad nand gate (74HC00) to get your 4 bit output. The inputs are active low, and so are the outputs, hence the need for the nand gates.

Wire the 'EI' input of the msb (the IC with inputs 8-15) to ground, and the 'EO' out to the 'EI' input of the next stage, which is the 0-7 inputs. The nand gates sum the 3 bit outputs and use the 'EO' output of the msb to drive the 4th nand gate, the msb of 4. The unused pin of gate 4 should be tied to logic 'High'. Now you have 3 IC's to get the output you want.

EDIT: To convert this binary output (which is not latched) to decimal requires a simple PIC MPU and the LED type number displays. If you can find an old TIL311 hexadecimal display on the market it will give you the hex value at the nand gate outputs.

The decimal display requires software to convert to decimal format, first latching in the newest hex value entered, then convert to a format compatible with the LED's, or you can output 2 BCD values and have them drive 2 7447 or 74LS47 BCD to 7-segment LED number displays.

You would need 10 to 15 IC's to latch, compare, convert to decimal then 7-segment LED drive output. With software you only need 1 to 3 IC's to do the same.