BCD subtraction woes

Discussion in 'Homework Help' started by mentaaal, Jan 5, 2008.

  1. mentaaal

    Thread Starter Senior Member

    Oct 17, 2005
    451
    0
    You guys are probably all going to hate me for bringing all my electronics blues to you but you guys are the best what can i say ;)

    I am having a tough time trying to understand this circuit. Its function is to perform binary addition/subtraction. I understand the addition part perfectly but when i try to do subtraction i dont get the right answer at all!

    Say for example when attempting to subtract 5 from 4. +5 in BCD is 0101Therefore -5=0101 as well (ten's complement)

    So 0100
    + 0101
    = 1001

    As this is a valid BCD code, no further action is taken (adding six on to this if the code was invalid) So obviously this is wrong so what am i doing wrong? I just cant seem to understand this circuit with respect to subtraction. Help!
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,178
    1,799
    Isn't 1001 the same as -1 in 10's complement notation?
     
  3. mentaaal

    Thread Starter Senior Member

    Oct 17, 2005
    451
    0
    Thanks papabravo! I think my problem here is that i was studying waaaaay past my bed time!

    I think that one thing that was bothering me about this circuit is that it doesnt provide the means to tell you if your answer is a negative or not. Does it? LIke say for example 9-4 = 5 which is positive = 0101.

    Whereas 0-9 is equal to -9 = 0001 I would i have known to do this conversion without looking at the original sum anyway?
     
  4. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Isn't it the case that in signed math the high-order bit is the indicator of whether the number is positive (0) or negative (0)?

    hgmjr
     
  5. mentaaal

    Thread Starter Senior Member

    Oct 17, 2005
    451
    0
    Ah yes i think i get it now, During a subtraction the carried bit would normally be disregarded but here it shows the sign, if a carry was generated, then the end result is a positive whereas if no carry was generated in the subtraction then the result has to be a negative. Cool thanks, I dont think that we were ever told this!
     
  6. Papabravo

    Expert

    Feb 24, 2006
    10,178
    1,799
    That may be true in binary. In BCD you have to look at complete digits to get the same sense. In a one digit BCD system I think the signed range is [+4..-5] or some such thing. I could be wrong though.
     
  7. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    I think you are correct in your comments. BCD does introduce a bit more complexity into the process. My earlier comment is more appropriate to binary math. I don't recall doing any 10's-complement math now that I think about it.

    hgmjr
     
  8. Papabravo

    Expert

    Feb 24, 2006
    10,178
    1,799
    It might be a bit easier to see if you think about two digits. In unsigned notation you have 00 to 99. So far so good. In unsigned notation that same range would represent -50 to +49 and the signed number line would look like the following:
    Code ( (Unknown Language)):
    1.  
    2. Maximum - .. 50 51 52 .. 99 00 01 02 .. 48 49 .. Maximum +
    3.             -50          -1  0  1  2    48 49
    4.  
    The rule for taking complements in base 10 follows the same rules for base 2. Take the 9's complement and add 1.

    (01)' = 98 + 1 = 99
    (50)' = 49 + 1 = 50

    Extending to more digits is child's play
     
  9. lotusdeity87

    New Member

    Feb 24, 2008
    3
    0
    Hi,

    I am having some trouble with BCD subtraction as well.

    I understand how to take the 10s complement and add it to the other number. But, I dont really understand what to do with the extra digit -- do you ignore it? Here are some examples I worked out which might illustrate my problem:

    1) 13 -5

    0001 0011
    +0000 0101
    0001 1000

    We get "1" and "8" but what to do with the 1?

    2) 8-13 = 8+(-13) where 10's comp of -13 is 100-13 = 87

    0000 1000
    +1000 0111
    1000 1111 <-- invalid so add 6
    +0000 0110
    1001 0101

    which is "9" and "5" but it should be -5 ... so I really dont know what to do in this case.


    3) 26-84 = 26+(-84) =-58 and the 10s comp of -84 is 100-84 = 16

    0010 0110
    + 0001 0110
    0011 1100 <-- invalid so add 6
    + 0000 0110
    0100 0010

    which is "4" and "2" and is clearly no -58.

    Thank you very much.
     
Loading...