We often hear technology stories about how many billion transistors a so-and-so chip is made of. Yes, THE CPU is a large scale integrated circuit, by the number of super many transistors, and the transistor only "on" and "off" two states, just can use "0" and "1" to represent these two states, so the CPU is the use of binary to carry out operations.
What is a CPU?
CPU is short for Central Processing Unit. The CPU consists of operation logic, registers and control components, which can interpret instructions and perform data processing. All instructions and data need to be made up of zeros and ones because the CPU itself is a super-sized digital circuit that only recognizes zeros and ones.
How to operate binary with only "0" and "1"?
All operational logic can be understood as "and", "or", "not", "xor"
And gate: among many conditions, all conditions are true.
1 and 1 = 1
1 and 0 = 0
0 and 0 = 0
Or gate: multiple conditions, as long as one of the conditions is true, it is true
1 or 0 =1
1 or 1 =1
0 or 0 =
Not gate: in fact, is the reverse phase
not 1 =0
not 0 =1
Xor gate: can be understood as, two conditions are not the same, it is true
1 xor 1 =0
1 xor 0 =1
0 xor 0 =0
Of course, can also be extended by these four doors "and not door", "or not door", "and or not door", "xor not door".
Why can the CPU run our program?
It says the CPU only knows "0" and "1", so why can it run our program? It is true that the CPU cannot run the programs we write directly. But if you directly use the combination of "0" and "1" to write a program, it is quite annoying, it is difficult to find errors, is very unrealistic. In order to solve this problem, intelligent human beings invented assembly language, replacing "0" and "1" instructions with characters that are easy to understand and remember.
Such as:
ADD: logical addition or subtraction
MOV: indicates data transfer
JMP: indicates the jump
Of course, the assembler still needs to translate these programs written in assembly language into hexadecimal machine code composed of zeros and ones.
With the development of computer technology, writing programs became more and more complex, and it was found that the efficiency of writing programs in assembly language was also quite low. Then intelligent human beings invented various high-level languages we use now, such as C,C++,PHP,Python and so on. Of course, programs written in high-level languages need to be "translated" by the compiler into hexadecimal machine code that the CPU can recognize.