Ever wondered how computer actually works under the hood? Of course I had a same question for myself, and this question actually lingered in my head for a quite some time. And recently, in an event of me trying to learn more deeply about Computer Architecture, this question was raised again. So I could not help myself but to learn more about this.
My question actually started after watching the movie 'The Imitation Game'. The movie portrays an early stage of the computer really well, and it was some what my first time able to see how and imagine how would've the early computers would've looked like in the past. The question rose when I saw the light switches.
After the movie, I asked myself. How does light switches actually works? In other words, how does 0s and 1s actually compute and works inside the computer?
So I shamelessly ask ChatGPT about this, and here's what I've learned.
tl;dr: Given a simple calculation ex - 1 + 2, the computer technically does not calculate 1 + 2 and gives 3 an answer. It changes it's states of the switches which represents the 3.
The longer answer
When I first tried to understand how does a computer really computes the a simple calculation like: 1 + 2, I initially thought, there has to be some kind of way that does the "calculation". But as I kept digging deeper on this topic, I realized that the concept of this calculation is different to what I've thought.
With human brain, when we calculate the 1 + 2, we can imagine there is one banana and we add two more bananas so it becomes a three bananas, which is the result. But in the world of computers, the concept of computation takes a different approach, which explains how a computers calculate such calculations like such with 0s and 1s.
To understand how the computers approach the computation, there are two important factors that we need to grasp:
- At the end of the day, what it means for a computer to compute is that the computer is simply switching switches on or off.
- And the result state of that is interpreted as a specific value.
Logic Gates
At a high level, most instructions when computer computes fall into these categories:
- Add
- Compare
- Move
- Manipulate the bit
These behaviors are realized by logic gates like AND, OR, XOR and NOT etc.
With simple addition like 1 + 2 works with XOR + AND, all the advanced and intricate activities such as adding a file, rename a folder is all happens with a combination of XOR, AND, NOR, OR, etc.
Say we created a folder. Under the hood, the computer enables bunch of sequence of logic operations and reaches a specific state of switches turned on and off. Now conceptually, in an OS level, we can call 'created folder', but under the hood, it is all clever combination of Add, Compare, Move and Manipulating the bit, but we represent this end state as a the result (folder being created)
State
So going back to the 1 + 2 calculation, we can say that when computer runs this, it activates a sequence of logic gates and reaches a result state of switches where specific switches are turned on and off, which is interpreted as the vaue 3.
Conclusion
So what I've learned is that the computer technically does not calculate like humans do. It bascially changes the state into another after going through sequences of logic operations. And the result is then interpreted as a value. ChatGPT calls it: "deterministically state transitions."