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?

968 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

For everything a computer knows how to do, it does these things based on some combination of CPU instructions. The instructions themselves are not software. They are tiny little electronic machines that perform well defined and simple operations like adding.

You could easily build a simple mechanical machine to add two 1-bit binary numbers. The adding part of a CPU is just 64 of these in electronic form chained together.

The tricky part is how the other operations are implemented. Sometimes, there are dedicated parts of the CPU that can handle those operations just like adding. Othertimes, they are partially implemented in software and partially implemented as simple electronic machines on the CPU. Part of CPU design is how complex or simple the instruction set should be.

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