Home New Stuff Author Links Guest book Web-log Adverts Bric-a-brac Calculators Components Ephemera Events For Sale Glossary History Hit or Miss Radios Transport Ultra Vales Wanted Metal Puzzles Articles Clocks

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