Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

BCD to Binary using Logical Devices

Status
Not open for further replies.

torkild

New Member
Hi
I want some help converting a BCD code to binary code.
I have 3 blocks producing converting BCD to Binary code(4 bits),thats not the problem.
The problem are to get the values from thoose 3 BCD decoders producing a 4 bit binary code to become one binary code.
Example i want the digit in BCD code 127 to be presented as 11111110 in binary. The first number 1 gives me a code of 00000001 in binary form.The second number 2 gives me the code 00000010 in binary code abd the last number 7 gives me 00000111 in binary code.
How do i combine thoose three binary codes to become 11111110 which is 127 in BCD code.

The full adder and half adder doesent work , or is it a easier way to do this from BCD to binary.

Its important that its done using logical circuitd(AND,OR,XOR and so on)

Also sending some photos of a working BCD to binary for 4 bit code as explained above.
 
I don't understand converting BCD to 4-bit binary. BCD is 4-bit binary. :confused:

There is no easy way to convert BCD to binary. To convert 3 digits of BCD to one binary word requires a huge amount of logic if you are limited to using only logical gates. You would need to generate a truth table for all 999 states and then convert that to logic using Boolean algebra.

Using a adder would require first multiplying the second BCD word by ten and the third BCD word by 100 before you add them all together, and multiplying is a sequential process (shift and add), not a static one.
 
I don't understand converting BCD to 4-bit binary. BCD is 4-bit binary. :confused:

There is no easy way to convert BCD to binary. To convert 3 digits of BCD to one binary word requires a huge amount of logic if you are limited to using only logical gates. You would need to generate a truth table for all 999 states and then convert that to logic using Boolean algebra.

Using a adder would require first multiplying the second BCD word by ten and the third BCD word by 100 before you add them all together, and multiplying is a sequential process (shift and add), not a static one.

I only have to count up to 127 (1 Byte). Ive found a way but like u say u need a lot of circuits. There must be someone who have done this only using logical circuits.
One way is to look at the bite that make the difference between 9 and 10 in BCD code, 19 and 20 in BCD code and so in. Multiplying first the first two 4 bit BCD code in binary form, then adding the last value of the cascade (0-9)(10-20)(21-31) and so on . Using some AND gates looking at the 2 MSB can help u determing where in the code u are i think. I shall try it out.

Any other ideas are welcome:)
 
Last edited:
OK, then your truth table would have 127 entries not 999 as I previously stated.
 
Last edited:
Example i want the digit in BCD code 127 to be presented as 1111 1110 in binary.
How come 127 (i assume this to be in packed bcd format) to be equal to 1111 1110 in binary?

I only have to count up to 127 (1 Byte).
Are you to convert or to count? 127 is 1 byte?
 
my goal is to use this with a PLC. diffrent BCD codes emerges and get transformed as binary at the output.
Anyone have the logical code ?
 
Why not just think boxes instead of wasting all brain cells on counting all possible states?

How about making four separate BCD - binary encoders. Then using four sets of adders to make the sum of binary.

Oh, one more thing. You need three circuits to multiply the different binary numbers by 10d, 100d and 1000d. :D
 
Another trick is to make the BCD counters up/down counters. When it is time to convert the BCD to binary, down-count the BCD counters to zero at the same time you up-count a binary counter. When the BCD counters reach zero, the value in the binary counter will match the numerical BCD value, but be in binary...
 
Another trick is to make the BCD counters up/down counters. When it is time to convert the BCD to binary, down-count the BCD counters to zero at the same time you up-count a binary counter. When the BCD counters reach zero, the value in the binary counter will match the numerical BCD value, but be in binary...
I agree.

I posted the opposite in this thread some time ago. See post #11.

https://www.electro-tech-online.com...to-decimal-into-dual-7-segment-displays.6591/

This circuit could be modified to do what Mike is suggesting.
 
The conversion is simply written: Binary = BCD1 + 10 * BCD2 + 100 * BCD3

This can be converted to power-of-two multiplications and adds, thus: Binary = BCD1 + 2 * BCD2 + 8 * BCD2 + 4 * BCD3 + 32 * BCD3 + 64 * BCD3. The multiplications are done just moving the wires of the BCD data lines.

my goal is to use this with a PLC. diffrent BCD codes emerges and get transformed as binary at the output.
Anyone have the logical code ?
If you're using a PLC, it should be pretty straight forward. What language are you using?

I guess the following might work for the conversion in VHDL (once you've defined the inputs and outputs), not that I have a clue:
Code:
output <= unsigned(bcd1) + 10 * unsigned(bcd2) + 100 * unsigned(bcd3)
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top