Binary subtraction

Discussion in 'General Electronics Chat' started by Nabla, Sep 17, 2008.

  1. Nabla

    Nabla Thread Starter Member

    Joined:
    May 7, 2008
    Messages:
    12
    I've been looking at digital arithmetic, and have easily understood addition using half adders, full adders and arrays of full adders, but when it comes to subtraction I don't really get it.

    My book shows a circuit for a half subtractor, that is exactly the same as that for a half adder, except the "minued" input (The input 'A', in 'A-B') to the AND gate (Borrow output) is inverted.

    The main thing I don't understand is the idea of 'borrowing' a bit. I mean when you 'carry' a bit in addition, you will only ever directly affect the next higher significant bit, but the way I learnt to do subtraction when I was little means that if the next higher significant digit is a zero, then you have to affect the next higher significant digit to that, and so on, until you come to a non-zero digit. When I've done some binary subtractions on paper the same thing applies.

    But how can a full subtractor, which is connected only to its next higher significant bit (and lower significant), take account of this standard subtraction algorithm*, when the next higher significant bit is a zero? It means having to change even higher significant bits, that it's not directly connected to. So how can it do it?

    Basically I'm having trouble connecting the hand calculations of binary subtraction, to the way the circuits work. I'm aware there are a few different subtraction algorithms that are used, using modular arithmetic and stuff, so I'm not really sure which is the best to learn. For instance I'm not sure that all of them will allow negative differences, which is probably needed for most applications.


    *This is an example of what I mean by this subtraction algorithm (in binary):

    Code:
    01101011
    -0110010
        1001
    
    Until this point there is no problem, but then we have for the 4th bit, 0-1, so we must look at the 5th bit. We can 'borrow' this bit, and have the sum 10 - 1 (in decimal 2-1) which equals 1, and lowers the '10' to '01', meaning the '1' in '10' becomes 0....like so:

    Code:
    01001011
    -0110010
       11001
    
    We then have to repeat this cause we have again, 0-1, so we end up with:

    Code:
    00001011
    -0110010
      111001
    
    (where I have changed the upper value to acoount for borrows).

    So we have 1101011-110010 = 111001 which in decimal is 107 - 50 = 57

    I'm ok with this so far, since we have only had to affect the bit immideately higher to the one we're computing, and in the circuit of a full subtractor, this is accounted for by the borrow-in connection.

    But what if we change the sum slightly to:

    Code:
     
    01001011
    -0110010
        1001
    
    At this point, we must borrow again from the next bit since we have 0-1, but the next bit is '0', so we must go to the next non-zero bit, '1'. We then have the sum, 100-1 (4-1 in decimal) which equals 011 (3 in decimal). So we have:

    Code:
     
    00101011
    -0110010
       11001
    
    This is the whole point I'm trying to make: In this sum we have not only had to increment the next highest significant bit, (bit 5, which changed from 0 to 1), but also had to go even higher to the next bit and change that (Bit 6 changed from 1 to 0)....but in an array of full-subtractors, each subtractor is only connected to consecutive bits, so how can it be possible to perform a sum like this, where non-consecutive bits are being directly affected as well?

    Thanks
  2. mik3

    mik3 Senior Member

    Joined:
    Feb 4, 2008
    Messages:
    4,846
    Location:
    Cyprus, but now in UK (GMT+0)
    Each circuit (here a subtractor) is designed to perform a specific function. Now, a 4-bit subtractor for example can not subtract a number with more than 4 bits. Thus the subtractor will borrow bits until it does not need to borrow more or it has reached the last bit and it can not borrow more.

    Think like that:

    The second bits stage says: "Did the first bits stage borrowed from me?" If yes it performs the appropriate function, if not it performs another function.

    Then it says: "Do i need to borrow from the third bits stage?"
    If yes it requests a borrow bit from the fourth bits stage, if not it does not request anything.

    By taking into account these two questions the same time it designs whether to request a borrow bit from the next stage or not.

    Each stage works in the same manner. Think of it!
  3. Nabla

    Nabla Thread Starter Member

    Joined:
    May 7, 2008
    Messages:
    12
    Hi Mik3, thanks for the comment, I understand that to perform an addition or subtraction on an n-bit number, you need an n-bit adder/subtractor, but my confusion is with the individual actions and connections of full subtractors with regards to the subtraction algorithm shown above.

    I have drawn a 4-bit subtractor in paint to try and emphasise my point:

    [​IMG]

    Where the sum is A-B, D represents the differences for each bit, and B in/B out are Borrow-in/Borrow-out respectively.

    This seems to contradict the sum I did above using the subtraction algorithm I'm familiar with.
  4. Nabla

    Nabla Thread Starter Member

    Joined:
    May 7, 2008
    Messages:
    12
    I figured out that the subtractor circuits I have been looking at work on a different algorithm to the one I have shown above, whcih also explains the inverted input to the AND gate. Case closed! :)
  5. mik3

    mik3 Senior Member

    Joined:
    Feb 4, 2008
    Messages:
    4,846
    Location:
    Cyprus, but now in UK (GMT+0)
    In the circuit above, each FS stage will borrow form the next FS stage and so on. Dont think of it that the FS0 has to borrow from all the following stages.
  6. Nabla

    Nabla Thread Starter Member

    Joined:
    May 7, 2008
    Messages:
    12
    I've realised that I've been looking at two different methods of subtraction....one is the method of complements, and the other is the method of borrowing each of which has it's own circuit.

    The method of complementing works by addition of positive numbers, and simply uses full adders and inverters, and I understand this method completely. The circuit looks like this:

    [​IMG]

    When the control line is 1, each bit of B will be inverted, else it will remain the same, so this switches between addition/subtraction.

    What I still don't get at all is the method of borrowing.

    But think about doing an actual hand calculation of subtraction in binary (or decimal, or whatever) using borrowing....as I demonstrated previously with my example, you may have a case where the bit you need to borrow from is 0...in which case you then borrow from the next higher bit.


    Here is the circuit I've been looking at for borrowing:

    [​IMG]

    Note: this is NOT the same circuit as above, since it is the borrow part of A that is inverted, rather than the whole of B (which is its 'one's complement'). Each of these full-subtractors is joined together as I have shown in my first diagram.

    Perhaps sources using this diagram for borrowing simply fail to mention this problem of borrowing from 0, since complementing is a more effective method anyway?

    Otherwise, it's obviously me that doesn't get it. In that case could you please walk me through the subtraction:

    Code:
     1001
    -0110
      011
    
    using the above circuit? Thanks alot
Similar Threads
Forum Title Date
General Electronics Chat IC Binary Counters with limited frequencies? Dec 13, 2014
General Electronics Chat Binary inputs to select output Jul 14, 2014
General Electronics Chat binary multiplier logic gates is a shift register required Feb 28, 2014
General Electronics Chat 8 Bit Binary Counter w/Register Oct 25, 2013
General Electronics Chat how do computer convert binary code Jun 25, 2013

Share This Page