Need help. 8 bit binary to bcd conversion

Ian0

Joined Aug 7, 2020
4,902
Is this a hardware adder?
It needs a lot of logic - I would be tempted to program a lookup table into a parallel EPROM. Unfortunately, for 8-bit binary in, you need 10 bits of BCD output
 

Thread Starter

royashley99

Joined Nov 20, 2021
43
It is a hardware adder, and I'm not sure how to program a EPROM in that way, could you use a 74LS90 for example to convert inary to bcd?
 

Ian0

Joined Aug 7, 2020
4,902
74LS90 is just a counter. It counts in BCD. It's not going to help you.
If you have a hex editor you can create the file for the EPROM. Are you hoping to get over 100? In which case you will need more than 8 outputs, which will be a problem.
If you connect your 8-bit binary number to the address lines A0 to A7 on the EPROM, then each binary number on those lines will make the EPROM output the stored data for that address on its output lines.
So if you binary number is, say 17, 0b10001, 0x11, then D0 to D7 will have the contents of memory 17.
Make your data table to give the BCD representation of the number, which is easy, because the bcd representation of 17 is 0x17.
It's probably not as instructive as getting to grips with the Karnaugh maps to do it in logic, but it gets to the answer rather more quickly!
By the way, was the purpose of converting to BCD so that you could display the output on 7-segment displays? If so, you can make the same EPROM do that as well.
 

Ian Rogers

Joined Dec 12, 2012
988
There "used" to be a 74ls185 and a 74ls184 Rocking horse do do now..
I use a little GAL to do this now .. An AM16V8 and it works the same as those old chips..
 

LesJones

Joined Jan 8, 2017
3,702
Another possible solution would be to Have an 8 bit binary counter and three divide by 10 counters (Such as 7490) clocked by the same clock pulse.
Have the outputs of the 8 bit binary counter connected to one set of inputs to an 8 bit comparator. the other 8 inputs of the comparator would be connected to the binary number that you want to convert. The two counters would be zeroed and the clock generator started. when the comparator circuit showed a match condition it would stop the clock input to both counters. At this point the three decimal counters will give the BCD value. This requires a lot of components compared with the EPROM method but it may be easier for you to understand. A small micro controller would be the cheapest way to do the conversion but you would have to learn how to write the code.

Les.
 

crutschow

Joined Mar 14, 2008
29,537
A variation of Les's solution is to use binary down-counters and BCD up-counters.
A the start you load the binary number into the down-counters and zero the up-counters, then have them all count simultaneously until the down-counter reaches zero.
The BCD counters will then contain the desired number.

Below is an example circuit for two BCD digits:
It uses CD4029 up-down counters which can count either binary or BCD.
For three digits, just add one more BCD counter.
The binary counter is shown be loaded with a binary 00010011 (this would come from your 8-bit adder).

1637419033765.png
 
Last edited:

MrChips

Joined Oct 2, 2009
25,949
I was thinking the same thing as well. Here are your options:

1) Discrete digital ICs - lots of chips
2) 3-digit BCD counter - lots of chips
3) Two EPROMs - 2 chips, need EPROM programmer
4) FPGA - 1 chip, need to learn FPGA programming
5) MCU - 1 chip, need to learn MCU programming
 

dl324

Joined Mar 30, 2015
14,356
I recently made a 8 bit adder and I'm wanting to convert the 8 bit out put to bcd, what is the easiest way I could do this?
Are you breadboarding the circuit? Or just simulating. If it's a simulation, implementing the logic for the Double Dabble algorithm isn't too onerous.

The method National Semiconductor, and others who sold 74185, used was a look-up table.

I think the easiest for breadboarding would be a look-up table in a 16 bit wide EPROM. I used an M27C4002. On the DIP part, all of the addresses are on one side and the outputs on the other and they're in order.
1637425420224.png
 

Ian0

Joined Aug 7, 2020
4,902
If you've built ONE 8-bit binary adder, you can convert to BCD if you build three more!
Each 10 has to become 16, so the most significant 4 bits have to be multiplied by 6 and added. Then if the LSB is greater than 9, you need to add 6 more.
You're probably thinking "now I need a multiplier" but it's not that bad.
To multiply by 6, multiply by 4 and add, then multiply by 2 and add.
To detect if the LSB is greater than 9, test if the 8 bit is high AND either the 4 or the 2.
I think it gets the right answer, but someone will no doubt tell me if it isn't.B3818275-DF81-4411-8A78-5E30709C788F.jpeg
If you want to go beyond 99, you’ll need 10 bit adders.
[Edit] if you want to go beyond 99, you will need more adders. As it stands it will output 0xA0 for an input of 100.
 
Last edited:

MrChips

Joined Oct 2, 2009
25,949
The EPROM solution is just a look-up table stored in memory.
You have 256 locations outputting 10-bit values. You will need two chips since the memory chips output 8 bits only.

It's just a list of numbers
0x000
0x001
0x002
0x003
0x004
0x005
0x006
0x007
0x008
0x009
0x010
0x011
0x012
0x013
0x014
0x015
0x016
0x017
0x018
0x019
0x020
0x021
:
:
0x255

One chip outputs 8 bits for the two LS digits, 00 to 99 (decimal).
The second chip only needs to output 2 bits, i.e. 00, 01, 10 (binary)
 

ericgibbs

Joined Jan 29, 2010
15,378
Hi 99,
If you are planning to use an EPROM on an actual project, you need a EPROM programmer.

Do you have a programmer unit.?

E
 

LesJones

Joined Jan 8, 2017
3,702
You would connect the 8 bit (Binary value) to the address lines of both EPROMS. You would use data bits 0 to 3 of the first EPROM for the units digit BCD display. Data bits 4 to 7 of the first EPROM would be for the tens BCD display. Data bits 0 to 3 of the second EPROM would be for the hundreds digit of the BCD display. This method is just creating a lookup table.

So the table would start like this.
Eprom address --- EPROM 2 bits 0 to 03 --- EPROM 1 bits 4 to 7 --- EPROM 1 bits 0 to 3
Binary -------------- BCD hundreds--------- BCD tens ---------------- BCD units
0x00 ---------------------- 0 ------------------- 0 --------------------------- 0
0x01 ---------------------- 0 ------------------- 0 --------------------------- 1
0x02 ---------------------- 0 ------------------- 0 --------------------------- 2
0x03 ---------------------- 0 ------------------- 0 --------------------------- 3
0x04 ---------------------- 0 ------------------- 0 --------------------------- 4
0x05 ---------------------- 0 ------------------- 0 --------------------------- 5
0x06 ---------------------- 0 ------------------- 0 --------------------------- 6
0x07 ---------------------- 0 ------------------- 0 --------------------------- 7
0x08 ---------------------- 0 ------------------- 0 --------------------------- 8
0x09 ---------------------- 0 ------------------- 0 --------------------------- 9
0x0A ---------------------- 0 ------------------- 1 --------------------------- 0
0x0B ---------------------- 0 ------------------- 1 --------------------------- 1
0x0C ---------------------- 0 ------------------- 1 --------------------------- 2
0x0D ---------------------- 0 ------------------- 1 --------------------------- 3
0x0E ---------------------- 0 ------------------- 1 --------------------------- 4
0x0F ---------------------- 0 ------------------- 1 --------------------------- 5
0x10 ---------------------- 0 ------------------- 1 --------------------------- 6
0x11 ---------------------- 0 ------------------- 1 --------------------------- 7

And so on.

Les.
 
Top