| Well a simple say one function calculator is very easy. Transistors are what make it all work. A transistor has 3 leads on it, if a current is going through the center lead, then it connects the other 2 leads allowing a current to pass through them. It is possible to link transistors in such a way that we can obtain AND, OR, XOR operations as well as the negations of these operations, these are called gates. Alright now a little rundown of gates. Each gate can have many inputs but produce one output. An input or output is a 1 or a 0, 1 being that a current is flowing and 0 being that no current is flowing. Here are truth tables for the above gates:
AND
A | B | Out
0 | 0 | 0
0 | 1 | 0
1 | 0 | 0
1 | 1 | 1
OR
A | B | Out
0 | 0 | 0
0 | 1 | 1
1 | 0 | 1
1 | 1 | 1
XOR(exclusive or)
A | B |Out
0 | 0 | 0
0 | 1 | 1
1 | 0 | 1
1 | 1 | 1
Ok, those are the truth tables in the simplst form, consisting of 2 inputs (A and B) and an output (Out). Alright for the AND gate we see that the only time we get an output of 1 is when both of the inputs are one (when A 'AND' B both have currents). Otherwise we get an output of 0. Witht he OR gate we get an output when either A 'OR' B has a current going through it. Exclusive OR is a bit different. XOR gives an output of 1 when either A or B has a current, but the catch is that it can't include the other inputs. In otherwords if there are 3 inputs in order to get an output of 1 A would need a current but at the same time B and C would have to have no current, or B would need a current and A and C would have no current or C would need a current with A and B no current.
Ok now that I have explained the AND, OR, and XOR gates (rather badly...) how do we use these to add 2 binary numbers together? Simple lets take 2 numbers, 2 and 3. Added together we would obviously get 5. Lets see how this works:
2 = 0010 in binary
3 = 0011 in binary
Alright in binary there are only 2 numbers, 1 and 0 addition works the same way as it does with decimal numbers. For example 1 + 0 = 1, 0 + 0 = 0, 1 + 1 = 0. The last one might be a little confusing and I'll try to explain it. In decimal you have the numbers 0-9 so when you add 1 to 9 you get a 0 with a 1 carried over. This concept works the same way with binary since there is no number 2 in binary (only working with 0 and 1) when 1 and 1 is added together we put down a 0 and carry a 1 to the next column.
Back to the problem so we have 0010 and 0011 and we want to add them together. To do this we use an XOR gate. Take a look at the truth table again for an XOR gate, notice anything? Put a + sign between A and B and an equal sign after B and it will look like this:
0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 0
notice the 1 + 1 = 0, this gate produces the correct outputs for binary addition. So in order to add our numbers together we XOR each column of the problem
0010
0011
First we have A = 0 B = 1
XOR those for an output of 1 and no value for the carry (the only time we will get a carry value is with a 1 + 1 setup)
next we have:
0010
0011
XOR 1 and 1 to get an output of 0 and a value of 1 for the carry
next is :
00+1 (from carry)10
0011
XOR 1 and 0 (we get the one because of the previous carry value) for an output of 1 with no carry value.
next we have: 0010 0011
XOR 0 and 0 to get an output of 0.
So our final answer is:
0101
which just so happens to be 5 in binary.
So there you have it a simple one function calculator. Remember the AND, OR, and XOR gates are just composed of transistors, so we have this calculator without having to write any software for it, the hardware does it all. Subtraction is the same way, but it involves adding the negative of a number. For example we want to subtract 2 from 3 (3 - 2) so really what we are doing is adding 3 to -2. So using that other gates we are able to obtain -2 in binary and we go through the steps of adding 2 numbers. Sorry for the long explanation I don't know how clear I was but I was trying to type this in a hurry. |