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?

954 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

CPU cores are built (like, physically) to perform basic operations thanks to logical doors. It’s a series of electrical states and impulses, that goes one way or another in order to change the states. These states are binary, but by convention they are reunited 8 by 8 in what we call bytes. A byt can represent 16 different values, from 0 to F, which gives you hexadecimal. The second to last step is Assembly : Assembly is a set of core instructions that allows you to change from one state to another. For example, SET x will put x (any number) into memory state. And the last step, called user instructions (even if it’s automatic) or command prompts, are requests associated with a certain amount of Assembly instructions. Programming languages are sets of command prompts, usually written in readable English, that allows you to get the results you want, or build a layout up to even more complex instructions (algorithms, then programs, then operating systems).

So basically, from top to bottom : when you ask your computer to divide A by B, you send the instructions A, divide, B. They’re converted into Assembly : SET A, then several commands. These commands are built up as a series of binaries that are converted into electrical impulses, sent in specific places at a specific speed. And these impulses physically modifies the properties of your core. That’s possible thanks to semiconductors, especially silicium, that realigns its own atoms depending on electrical impulses. This leads to many physical movements (especially given the unbelievable speed of nowadays CPUs), that produces heat as an outcome. That’s why CPUs get so hot and need a cooling system : atoms dancing like devils in order to math for you.

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