Eli5: Computers can calculate based on instructions. But how do you teach computers what does it mean to add something, multiply, divide, or perform any other operation?

944 views

Edit: Most of the answers here are wonderful and spot on.

For those who interpreted it differently due to my incorrect and brief phrasing, by ‘teaching’ I meant how does the computer get to know what it has to do when we want it to perform arithmetic operations (upon seeing the operators)?

And how does it do it? Like how does it ‘add’ stuff the same way humans do and give results which make sense to us mathematically? What exactly is going on inside?

Thanks for all the helpful explanations on programming, switches, circuits, logic gates, and the links!

In: 583

43 Answers

Anonymous 0 Comments

little late, but i think I have a good explanation.

if you think of exponentiation as repeated multiplication, multiplication as repeated addition, then what is addition? – the answer is repeated boolean algebra operations. boolean algebra is a bit complex, but there’s a theorem that any boolean expression (such as a long one representing the addition of two numbers) can be rewritten to only use three fundamental operations; AND, OR, NOT*. these operations are SO simple that they can very easily be implemented in a circuit. actually we have an integrated circuit that’s so good at this purpose its the basic building block of every cpu – and its called a transistor. so by chaining millions of transitors your able to program a computer to do, for instance, exponentiation, or any other basic arithmetic operation at a macro scale. from there, any more complicated operation are just repeated arithmetic and can therefore be calculated with a deconstruction into boolean algebra. most significantly though, now that you’ve unlocked all of mathematics, you can control other pieces of electronics, such as a display, by calculating what color each pixel should be and letting the display circuitry do the rest.

* an AND operation is if you have two input wires, if and only if A AND B are both powered, should the output wire have power. an OR gate is the same thing as AND, but powered if A OR B is powered.
a NOT operation is the output is powered if and only if the input wire is not.

You are viewing 1 out of 43 answers, click here to view all answers.