New Stuff
Guest book


For Sale
Hit or Miss
Metal Puzzles


CalculatorsHow does a calculator work? (2 in progress)

Can I have an easy explanation please?
Well, I will give it a go, for those that are interested - served up in bite-sized chunks.  How a calculator works is how a computer works - they are the same thing really - just a bit more complex.

Item 1: Binary
OK, this is the basic maths bit.  If you hate maths (or think that you are no good at it, try it, you may be surprised).  Feedback welcome!

Calculators use a base-binary notation for numbers: these are numbers represented by ones and zeros (on and off). 
The easiest way to think of this is go back to your early school days when you were taught that to add one to nine, you must add a new "tens column".
So 9+1 = 10 (i.e. one ten, and zero units). This is called the decimal-based system.
[Factoid: Decimal is formed from the Greek Deca/Deka for ten, which is no doubt orientated around the number of fingers we have.]

Now if you only had two numbers to play with you would have to add a new column every "third number". Think about this, as once you can get this, the rest is easy.

So in binary:
0 = 0
1 = 1
2 = 10 (one two, and zero units)
3 = 11 (one two and one unit)

now if I put a zero for the "number of twos column"
0 = 00
1 = 01
2 = 10
3 = 11

it looks slightly more obvious. 

Each digit is called a "bit", so to represent the number 3, you must have a least two "bits".

But what about bigger numbers?  Well you just carry on adding columns (as you would with thousands, tens of thousands and so on).

0 = 000
1 = 001
2 = 010
3 = 011
4 = 100
5 = 101
6 = 110
7 = 111

Now if you look carefully at the columns, adding one all the time creates a pattern: the first column (to the right) changes every number, the next column changes every two numbers, the final column (on the far left) changes every four numbers. Electronic circuits love patterns!

One last thing: if we only had two digits, we could refer to the number 4 as "00" plus "carry one", like we used to carry a number in long multiplication.

Phew! that's enough maths for now, we will go deeper in later sections though.

Item 2: Gates
Calculators, computers and all digital electronic circuits are built up from Gates.  Gates let signals through according to rules.  Get the key rules right - and just like a padlock, the gate opens.

The simplest of gates has two inputs and one output result.  For electronic circuits the inputs are either zero (ie. zero volts) or one (i.e. five volts). Gates are made out of transistors, but that does not need to be gone in to depth right now.

Describing how a gate works is called Boolean logic, but is very simple really. 

Item 3: Important Gate Types
Here is a image of the basic logic gate. It has two inputs (A and B) and one output (Y).  This is an image of an AND gate.
An "And gate" will only give a (1) (i.e. 5V output) if A and B is (1) (i.e.5 volts).

So, to get technical, if:

A=0 and B=0 then Y=0
A=0 and B=1 then Y=0
A=1 and B=0 then Y=0
A=1 and B=1 then Y=1 (so the output (Y) is only 1 IF A and B = 1)

Here is a image of another logic gate. It has two inputs (A and B) and one output (Y).  This is a NAND gate. Note that the little circle always means the opposite signal (on an input or an output) is applied.
A "NAND gate" will be the reverse output of an AND gate (hence the N stands for negative).

A=0 and B=0 then Y=1
A=0 and B=1 then Y=1
A=1 and B=0 then Y=1
A=1 and B=1 then Y=0 (so the output (Y) is only 0 IF A and B = 1) - the opposite of above - easy!

And finally this is an "OR gate", the output Y is one if A or B is one
A "OR gate"  will give a (1) (i,e, 5V output) if A or B is (1) (i.e.5 volts).

A=0 and B=0 then Y=0
A=0 and B=1 then Y=1
A=1 and B=0 then Y=1
A=1 and B=1 then Y=1 

There are more complex types like NOR, XOR, inverting buffers and negative single input/multiple input gates that need not worry us here. Phew, enough about gates!



Item 4: What the heck does Gate logic have to do with my life? It's all rubbish
I would agree with your initial feeling but...

Consider your burglar alarm.  You want it to go off if a front window is broken OR a back window is broken OR you door is open OR your panic alarm is pushed - this is a multi-input OR gate.

Your washing machine will only start drying if the wash cycle is over AND the sump is drained.  So Boolean logic surrounds us all day.

So we have learned how "on and off" voltages can make decisions for us in electronic gadgets.



Item 5: The adder circuit
Now, if you are clever enough, you can combine all these type of gates and make a circuit that adds two binary numbers together:

i.e. 0010+0001=0011 (2+1=3)

Don't worry too much about how this works - just believe me.

A1-4 are the inputs for the first number
B1-4 are the inputs for the second number
S1-4 are the output result
Cin and Cout are the "Carry one" flag mentioned above

Addert gate circuit
This circuit is a 4-bit adder, join two together and you get an 8-bit adder.  Modern processors are 64-bit adders.


Congratulations! You now know how a calculator/computer works.  That is it, they can only add stuff.  The rest of the things they do are merely extensions of adding two numbers together (albeit in very sophisticated and rapid ways).

Item 6: How to Subtract Numbers
This is more simple (I hope) than most descriptions tell you.

You have to take what is called the "two's-complement" of a number.

If you have the number 6, in binary we have learned that this is "0110".

Now, invert all the digits (so that 6 changes from 0110 to 1001) then add one to get 1010.

Now, this is really neat.  If you add 7+6 you get 13, but if you add 7+6(two's complement) and ignore the carry flag, you get 1, as it is 7-6.  So adding a two's-complement number is just like taking it away.

Just as before the gates to the right create a two's complement of a number. This allows you to subtract numbers by "adding" them.

Two's complement gate circuit
If you did not quite understand that then here is the basic statement.  By tweaking a digital number you can make it a negative number, so adding it is the same as taking it away.


Item 7: Registers (or short-term memories)
A calculator must "remember" what you have keyed in.  When you press 3+4 it must remember that you have pressed the number three and remember that you have pressed the number four and then go off an do the calculation.  These memories are called "Registers". They are called X and Y registers (Z is usually reserved for the answer).

So, when you key in 3+4:
Register X = 3
Register Y = 4 ... and eventually
Register Z = 7

So even the most basic of calculators has three internal memories or Registers.