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?

950 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

Imagine a lightswitch: flick the switch and the light goes on. This is a physical process because electricity has been directed due to the switch.

Imagine two light switches arranged such that both of them have to be ON for the light to be ON. Switch1 *AND* Switch2 must be on. This is called AND.

Imagine two light switches arranged such that either light switch would turn on the light. Switch1 *OR* Switch2 will turn on the light. This is called OR.

Imagine the same as the OR example, but either light switch will turn on the light provided the other switch is off. One switch will turn on the light exclusive of the other one. This is Exclusive OR or XOR for short.

All of these can be created with simple ON/OFF light switches and the exact same concepts can be created with transistors in computers because one of the uses for a transistor is as a switch.

This gets pretty complicated, but by combining these functions – we call them Logic Gates – you can do all sorts of math *with physical switches*!

In a modern computer those physical switches are transistors, and by putting them in certain orientations addition, subtraction, multiplication, and division are possible. Literal physical devices are built with transistors with names like ADDER that literally add based on these gates.

Early computers were made with relays that clacked away making these switching paths. I actually built one and it’s amazing to watch and listen to it it process programs without a CPU. Here’s a (https://www.youtube.com/watch?v=g1lPCwukqSw). Every click you hear is literally a switch changing position from ON to OFF or vice-versa.

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