All About Circuits Forum Binary subtraction
 Register Blogs FAQ Members List Today's Posts Search Today's Posts Mark Forums Read

 General Electronics Chat Discussion forum for general chat about anything electronics related, including asking questions about material in the All About Circuits E-book, Worksheets, and Videos.

#1
09-17-2008, 02:14 PM
 Nabla Junior Member Join Date: May 2008 Posts: 12
Binary subtraction

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```
Select All
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```
Select All
We then have to repeat this cause we have again, 0-1, so we end up with:

Code:
```00001011
-0110010
111001```
Select All
(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```
Select All
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```
Select All
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
09-17-2008, 03:23 PM
 mik3 Senior Member Join Date: Feb 2008 Location: Cyprus, but now in UK (GMT+0) Posts: 4,846 Blog Entries: 9

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
09-17-2008, 03:53 PM
 Nabla Junior Member Join Date: May 2008 Posts: 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:

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
09-17-2008, 06:27 PM
 Nabla Junior Member Join Date: May 2008 Posts: 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
09-17-2008, 06:37 PM
 mik3 Senior Member Join Date: Feb 2008 Location: Cyprus, but now in UK (GMT+0) Posts: 4,846 Blog Entries: 9

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
09-21-2008, 05:15 PM
 Nabla Junior Member Join Date: May 2008 Posts: 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:

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.

Quote:
 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.
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:

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```
Select All
using the above circuit? Thanks alot

 Tags binary, subtraction

 Related Site Pages Section Title Worksheet Digital codes Worksheet Binary math Textbook Look-up tables : Principles Of Digital Computing Video Lecture Binary Conversion - Converting Binary to Decimal - Digital Textbook A Full-Adder : Combinational Logic Functions Textbook 7-segment display : Digital Integrated Circuits Textbook Subtraction : Binary Arithmetic Textbook Negative binary numbers : Binary Arithmetic Textbook Decimal versus binary numeration : Numeration Systems Textbook Octal and hexadecimal numeration : Numeration Systems

 Similar Threads Thread Thread Starter Forum Replies Last Post alan-1981 Homework Help 3 03-01-2008 08:49 PM mentaaal Homework Help 8 02-24-2008 11:37 PM arthur92710 General Electronics Chat 86 02-23-2008 04:33 PM arthur92710 General Electronics Chat 7 10-24-2007 08:33 PM JoeyB Homework Help 3 03-22-2007 03:37 PM

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Electronics Forums     General Electronics Chat     The Projects Forum     Homework Help     Electronics Resources Software, Microcomputing, and Communications Forums     Programmer's Corner     Embedded Systems and Microcontrollers     Computing and Networks     Radio and Communications Circuits and Projects     The Completed Projects Collection Abstract Forums     Math     Physics     General Science All About Circuits Commmunity Forums     Off-Topic     The Flea Market     Feedback and Suggestions

All times are GMT. The time now is 11:15 PM.