Jump to content

Full Adder Question

Krocket

I've been interested in Adders and Binary for a long time now but am curious about something. Addition, subtraction, multiplication, division, etc. all require different types of adders right? Is there any type of adder that can take 5 inputs (The 2 inputs, carry, and then 2 more to tell which process you're doing) to make an all-in-one adder? I've made plenty of ones that can do addition, subtraction, and multiplication, and they all use the same basic gates and concepts, so if you just switch a few other inputs can't you change how the whole thing works? Kind of a newby question.

Link to comment
Share on other sites

Link to post
Share on other sites

Ah numberphile's video must have gotten you :P  If not go watch it, dominos on numberphile.

 

Anyways to answer a bit of your questions (and someone come in and correct any mistakes please, there are bound to be a few in what I am about to write)

 

Well let me first tackle the easy one, full adders with addition/subtraction.  When you subtract in a program it is merely doing this 10 - 3 = 7  turns into 10 + (-3) = 7.  So the subtraction is merely negating the second variable and adding.

 

An interesting note is how adding of a negative number is done.  It is done through a process of two's complement.  See the wiki for a more detailed description...it is a wonderful system really..but I will briefly explain ( So assume your binary is 4 bits long, and you want neg and pos values -8 to 7.  Now the trivial way to represent this system is the last bit is used as a sign (pos or neg).  This has a few problems though, the first being you have -0 and 0 (which actually is the case in floating point).  The other problem being 1 + -1 using a full adder is completely messed up...you would get -2

0001

1001 =

1010

So now where two's compliment comes in is for all positive numbers use the first 3 bits, for negative numbers you take 2 ^ 3 and subtract the value of the first 3 bits.  So 1111 = -1 1100 = -4...This has the happy consequence that full adders now work.

0001

1111 =

10000 (with clipping = 0000, which is the correct answer)

The math actually works so when adding two opposing number (121 and -121 for example) you will always end up with 0000....If you want to know more about why it works read the wiki article...but it was a brilliant concept which made the full adder work. (You could work out the reasoning using the numphiles type of logic as well I suppose).

 

 

Now getting onto the more boring stuff, multiplying and dividing.  What is 23 * 10? 230...easy right you just add a 0.  In binary it is just as easy when it is a power of 2.  1,10,100...you just has be shift over.  So a simple circuit for anything * 2 as pictured by dominos would be diagonal dominos and a single domino at the end that wasn't attached to anything :P

...100 * 10

..100[0] everything is just shifted 1 over and a 0 is added to the end.

Now this is actually called a shift.  So a shift left 1 would be like saying *2.  So with this you can now build a multiplier using this [shifts] and full adders.

 

e.g. 1001011 * 10101 can now be broken up into 5 parts

1001011 and       1 = 1001011

10010110 and     0 = 0  (Notice everything shifted left 1)

100101100 and   1 = 100101100

1001011000 and 0 = 0

10010110000 and 1 = 1001011000

 

So for each nth bit you just shift by n and and them together....and then finally you sum up all the end values to get your new answer.  More on this here (http://en.wikipedia.org/wiki/Binary_multiplier)

 

My memory is going on how the division is handled....it is actually a bit more complex than multiplication and it has been too long since I actually learned about it (I can't remember even what to google to find the answer :P so someone please help answer this).  This is what I remember though.  Binary division with a multiple of 2 is easy.

Divide by 2 you shift 1 right (ie 100101 becomes 10010...you just drop the last digit).  Divide by 4 just shift 2, 8 shift 3...etc.

 

If I had to guess, division would work very similar to how we do division in base 10.  e.g. 10 bits / 4 bit number.  Check if bits 10 9 8 7 (dividend) are larger than 4 3 2 1 (divisors) if so subtract...shift the number right by 1 and or together with 6.  so you you have [(10 9 8 7) - (4 3 2 1) shifted left 1] 6.  So then you repeat until you hit 1 on the dividend.  Sorry if this doesn't make sense.

 

*edit* To answer your other question, that is the job of the processor ;)  In effect you can make something that takes in lets say two 32 bit numbers and a 2 bit flag to tell it to add subtract divided or multiply...and to an extent you could make them even share a lot of logic gates most likely...but we are getting into more complex territory here :P

 

*edit again Oh thinking about it a bit today, I should probably have mentioned this works for only two's compliment types of systems (and other similar systems),  When you are dealing with floating point numbers (ieee specified) you actually don't use full adders (well in principle you do, but there are a lot more little funny things that are going on when you introduce floating point)

0b10111010 10101101 11110000 00001101

Link to comment
Share on other sites

Link to post
Share on other sites

I'm not too knowledgeable on this matter, but once you have a functional full adder then you can do any math out there. As mentioned there are more effective ways to do multiplication, division, and beyond. If I were designing my own CPU (which is on my bucket list) then I would start with a run of the mill full adder and follow the principles in this video which does an amazing job of describing how all math is built on addition: 

 

My rig: 2600k(4.2 GHz) w/ Cooler Master hyper 212+, Gigabyte Z68-UD3H-B3, Powercolor 7870 xt(1100/1500) w/AIO mod,

8GB DDR3 1600, 120GB Kingston HyperX 3K SSD, 1TB Seagate, Antec earthwatts 430, NZXT H2

Verified max overclock, just for kicks: http://valid.canardpc.com/show_oc.php?id=2609399

Link to comment
Share on other sites

Link to post
Share on other sites

Ah numberphile's video must have gotten you :P  If not go watch it, dominos on numberphile.

Haha, yes, I did see it but I've been interested in binary for about 3 years now, just not adamant in the research. Sorry for the late reply and thank you for the nice response btw. For some reason I'd never known what 2s compliment was and hadn't really worked much with the actual math part of binary, but rather the gates. And for what you said about the CPU and sharing logic gates is exactly what I was thinking of. I tried creating an adder with 2 'flags', as you put it, that would switch between addition and subtraction when the flags were switched but got lost in all the circuitry. Now that I know a little more about 2s compliment and the basics behind the math perhaps I'll be able to go a little further with it. I know anything I think of will have probably been created before but it's all in the fun of it  ^_^ Binary is such an awesome thing. Wish I could just absorb everything on it.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×