1. 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.
    Dismiss Notice

How to convert from Binary to BCD using logic work?

Discussion in 'Homework Help' started by forza_inter, Nov 20, 2010.

  1. forza_inter

    forza_inter New Member

    Joined:
    Nov 20, 2010
    Messages:
    7
    Likes:
    0
    I'm designing a 4-bit calculator with two input and they ( the inputs) are in BCD then i convert them to Binary.
    the problem is that after I get the output in binary I need to convert it in BCD.
    the output in binary will be 8 digits in BCD unless it was less or equal to 9( for example 3*9=27 and 27 is 0010 0111 in BCD)
    so that means I create another truth table for Binary-to-BCD with 8 outputs?!!!!! that doesn't make sense!
     
  2. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,049
    Likes:
    961
    Location:
    NJ
    Hello there,


    If you convert BCD to binary and do math then yes you need to convert back to BCD again to get the resulting answer into BCD form again. That's life.
    If you do BCD math then you dont have to convert again, but BCD math requires a lookup table for all of the operations. Im not sure what you are working with yet though so it's hard to recommend something right now. If you want to do it in binary then you have to convert back to BCD again either with your own ROM or with some discreet logic ic chips.
     
  3. crutschow

    crutschow Well-Known Member Most Helpful Member

    Joined:
    Mar 14, 2008
    Messages:
    10,623
    Likes:
    479
    Location:
    L.A., USA Zulu -8
    There is no shortcut to converting BCD to Binary and back. You either need lookup tables, an algorithmic computer program, or somewhat complex logic (see this).
     
    Last edited: Nov 20, 2010
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. forza_inter

    forza_inter New Member

    Joined:
    Nov 20, 2010
    Messages:
    7
    Likes:
    0

    yes I need to convert BCD-to-Binary and do math then convert the result which is in Binary to BCD in order to display it in 7-segment display.
    , so the output of Binary-to-BCD will be 8-bit ( for example 3*9=27 and 27 is 0010 0111 in BCD) I can't make a truth table with 8 output!!
     
  6. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,049
    Likes:
    961
    Location:
    NJ
    May i ask why not?
    Alternately, why cant you buy a couple binary to BCD ic chips?
     
    Last edited: Nov 21, 2010
  7. forza_inter

    forza_inter New Member

    Joined:
    Nov 20, 2010
    Messages:
    7
    Likes:
    0
    I have to use the logic work.
    so if i make a truth table with 8 outputs how can I get the logic gates for the truth table
     
  8. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,049
    Likes:
    961
    Location:
    NJ
    Hi again,


    You use a ROM chip and program it with your logic specifications.

    For example:
    Address: 00000000, Outputs: 00000000 (0+0=00)
    Address: 00000001, Outputs: 00000001 (0+1=01)
    ....
    Address: 00010002, Outputs: 00000003 (1+2=03)
    Address: 01110110, Outputs: 00010003 (7+6=13)
    etc.,

    which covers the math plus the conversion, or just to convert binary to BCD use:

    Address: 00000000, Outputs: 00000000 (binary 0=BCD 00)
    Address: 00000001, Outputs: 00000001 (binary 1=BCD 01)
    ...
    Address: 00010001, Outputs: 00010111(binary 17=BCD 17)
    etc.


    So in other words, two BCD numbers with 4 bits and 4 bits maps to 8 bits BCD and 256 or less locations doing addition math, and another 8 bits and 256 for multiply, etc., so you could do a four banger 2 digit calculator in an 8 bit by 1024 ROM.
    Or, using simple binary to BCD, binary codes for decimal 0 to 99 also map to 8 bits and 256 locations in ROM.

    The additions/subtractions/multiplies/divides take whatever time the ROM takes, which is usually quite fast but does depend on the spec's of the ROM chip.


    If you have to use logic gates then you'll have to figure out the conversion, or else look up the TTL logic chips that do the binary to BCD already and go from there. Only two digits shouldnt be too hard to accomplish.
     
    Last edited: Nov 21, 2010
  9. crutschow

    crutschow Well-Known Member Most Helpful Member

    Joined:
    Mar 14, 2008
    Messages:
    10,623
    Likes:
    479
    Location:
    L.A., USA Zulu -8
    I believe the chips that do binary-bcd conversion are no longer made, so it may be difficult finding a source for them.

    Edit: I believe those circuits used some form of built-in ROM look-up table to perform the conversion.
     
    Last edited: Nov 22, 2010
  10. forza_inter

    forza_inter New Member

    Joined:
    Nov 20, 2010
    Messages:
    7
    Likes:
    0
    I really appreciate your help MrAl
    I don't think I'm allowed to use ROM chips because I didn't study them yet as well as the TTL logic.
    I think the only way is by using logic gates which is confusing with 8 outputs and I don't know how to drive the Boolean expression from an 8-outputs truth table.
    thank you again MrAl :)
     
  11. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,233
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi,
    If you are able to get some 74184 or 74185 IC's you could make this circuit.
     

    Attached Files:

  12. forza_inter

    forza_inter New Member

    Joined:
    Nov 20, 2010
    Messages:
    7
    Likes:
    0
    unfortunately they aren't available in the logic work (or the version that I should work on)
     
  13. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,049
    Likes:
    961
    Location:
    NJ
    Hi again,


    This should get you started. This is the starting work for converting 4 bit binary to BCD. The inputs are a,b,c,d and the output bits are 7,6,5,4,3,2,1,0, where 3,2,1,0 are the units BCD digit and 7,6,5,4 are the tens BCD digit.

    We start by examining bit 0 for every possible combination of the inputs. Every time we see a '1' in that column we write a boolean expression for that bit based on each and EVERY input bit (although we later can skip 'a'). We do this with all 16 input combinations and thus we end up with 16 or less expressions, which we then logically "OR" together. We then try to simplify that expression using boolean algebra.

    You can see i already did bits 0 and 1, and you can also see that bit 0 reduced to simply 'a' (one input). Bit 1 was a little more difficult but that one only required a few expressions. Next, you can write expressions every place i put an asterisk '*' in the third truth table, then proceed to do the other bits the same way.

    You'll note that input bit 'a' is not required in the expressions after the first truth table. This is the way binary to BCD always works as an odd binary is also an odd BCD, and odd and even are determined by bit 'a' of the input, no matter how many bits you have to convert. This means for 4 bit conversion we only have to consider b,c, and d, and for 5 bit we would only have to consider input bits e,d,c,b, and so on.


    Code (text):




    INPUT  OUTPUT
    dcba   7654 3210
    0000   0000 0000
    0001   0000 0001   d'c'b'a
    0010   0000 0010
    0011   0000 0011   d'c'ba
    0100   0000 0100
    0101   0000 0101   d'cb'a
    0110   0000 0110
    0111   0000 0111   d'cba
    1000   0000 1000
    1001   0000 1001   dc'b'a
    1010   0001 0000
    1011   0001 0001   dc'ba
    1100   0001 0010
    1101   0001 0011   dcb'a
    1110   0001 0100
    1111   0001 0101   dcba

    Bit0=d'c'b'a+d'c'ba+d'cb'a+d'cba+dc'b'a+dc'ba+dcb'a+dcba
    which reduces to:
    Bit0=a


    INPUT  OUTPUT
    dcba   7654 3210
    0000   0000 0000
    0001   0000 0001
    0010   0000 0010   d'c'b
    0011   0000 0011   d'c'b
    0100   0000 0100
    0101   0000 0101
    0110   0000 0110   d'cb
    0111   0000 0111   d'cb
    1000   0000 1000
    1001   0000 1001
    1010   0001 0000
    1011   0001 0001
    1100   0001 0010   dcb'
    1101   0001 0011   dcb'
    1110   0001 0100
    1111   0001 0101

    Bit1=d'c'b+d'cb+dcb'
    which may be reduced also.


    INPUT  OUTPUT
    dcba   7654 3210
    0000   0000 0000
    0001   0000 0001
    0010   0000 0010  
    0011   0000 0011  
    0100   0000 0100  * write expression here
    0101   0000 0101  * ditto
    0110   0000 0110  * ditto
    0111   0000 0111  * ditto
    1000   0000 1000
    1001   0000 1001
    1010   0001 0000
    1011   0001 0001
    1100   0001 0010
    1101   0001 0011
    1110   0001 0100  *  ditto
    1111   0001 0101  *  ditto

    Bit2= (logically OR all your statements here and then reduce if possible)

     
     
    Last edited: Nov 22, 2010
  14. crutschow

    crutschow Well-Known Member Most Helpful Member

    Joined:
    Mar 14, 2008
    Messages:
    10,623
    Likes:
    479
    Location:
    L.A., USA Zulu -8
    See this thread for some other suggestions on BCD-Binary-BCD conversion. The last two submissions show some circuits.
     
  15. forza_inter

    forza_inter New Member

    Joined:
    Nov 20, 2010
    Messages:
    7
    Likes:
    0
    thx it's quite clear now.
    ,so I should make the all possible inputs in Binary (for example: from 1*1 (which is 0001), 1*2,1*3,.... 8*9,9*9. and for the addition ,subtraction and division as well) but it's gonna be too looooooong.
    or another solution is to make 82 inputs from 0 to 81 ( because the highest number I can get is 9*9=81) , am I right?

    thank you :)
     
  16. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,049
    Likes:
    961
    Location:
    NJ
    Hello again,

    Well with my previous post i was assuming you would do what you were doing to start with: go from BCD to binary and then math, then binary back to BCD, and my previous post was to get you started on the binary to BCD converter.
    You can write the equations for a full 7 bit to 8 bit BCD (2 digit BCD) as my previous post or write a 5 bit to BCD and use multiple instances of that circuit following along the lines of using a 74185 (look up that chip for more info). It will take a little work yes. I have a program i wrote a while back that creates boolean logic statements from a truth table but you should really learn how to do this yourself right?

    You know if you dont need super fast conversion times you can use an 8 input NOR gate and two binary 4 bit counters and two BCD counters and maybe a few other glue logic chips. You would set the binary counters to the number to be converted and reset the two BCD counters and then start pulsing the BCD counters UP and the binary counters DOWN until the binary count equals zero, at which time the BCD count would be the BCD representation of whatever the binary counters were originally set for. Thus, a binary count of 00010001 would cause a pulsing of the two BCD counters 17 times which means they would hold a BCD count of 1 and 7 which is the BCD representation of binary 00010001. With a clock rate of 1MHz this would take a maximum of about 100us to complete.
     
    Last edited: Nov 23, 2010
  17. forza_inter

    forza_inter New Member

    Joined:
    Nov 20, 2010
    Messages:
    7
    Likes:
    0
    I think I'm gonna write the equations for a full 7 bit to 8 bit BCD with all possible inputs from the operations although it's too long.
    thank you :)
     
    Last edited: Nov 23, 2010
  18. TeddySky

    TeddySky New Member

    Joined:
    Jul 24, 2012
    Messages:
    1
    Likes:
    0
    Thanks!

    Good evening everyone :)
    I had to make this account to thank MrAl.
    You send me in the right direction to learn to make logic diagrams.
    I have fun in solving Boolean expressions. Thank you so much!
    I learned how to make the 4 bit binary to BCD converter, but now I would like to make it 16Bit.
    Though writing a truth table that goes up to 720859 is going to take some time.
    I think there might be a better way :p
    Im guessing with shift registers? Ive try'd to google it but I cant find a good start
    Could someone please point me in the right direction?

    Thanks in advance
    Teddy
     

Share This Page