• “MoreThanJava” is about “learning, not just CODE”. This series of Java basics tutorials is a general review of the basics of Java by myself after combining all aspects of knowledge, aiming to “help new friends learn quickly and with high quality”.
  • Of course, both old and new, I believe you will benefit from it. If you feel “good” friends, welcome to “follow + message + share”, at the end of the article there is a complete link to get, your support is the biggest motivation for me to move forward!

Question: How to make people who don’t know programming feel the charm of programming?

Link: www.zhihu.com/question/40…

Part 0. Preface

Ask a similar question: “How do I make basketball fun for people who don’t know basketball?”


Obviously, the answer depends on people.

For some people, coding can be tedious and arduous, but for others it can be fun and rewarding.

Often, after you’ve written your code, it’s hard to tell if it’s boring or fun.

But we can do this by getting a better understanding of “what computer programming is,” so you can judge for yourself whether it’s fun.

At the current level of development, anything that has electricity involves coding;

Part 1. A brief history of computer development | to solve practical problems


  • The history of computing — from the loom to IBM

The beginning of all | loom

Clothing, food, shelter and transportation are basic human needs, and textiles and looms have been invented all over the world.

How to improve the efficiency of textile, become a very important topic.

Principle of weaving

Unlike “knitted fabric”, “woven fabric” consists of two or more sets of two systems of yarns or silk threads that are perpendicular to each other. The longitudinal yarns are called warp yarns and the transverse yarns are called wefts.

Through the interlacing of the two lines with different rules, different colors and changes in arrangement will be formed, which will bring about different patterns.


  • References from the picture: https://www.sohu.com/a/301616592_99894978

The original looms were done by hand.

Later, it was found that the changes of fabric patterns were always arranged in accordance with a certain rule. In the Warring States Period, a multi-heald jacquard loom was invented to accomplish this task by means of a heald frame:


This may be the most original coding: by putting the warp yarn with the same lifting rule into the heald yarn of the same heald frame, when a heald frame is lifted (completed by pedal), the thread expressing a specific pattern is lifted, and the weaving of specific pattern is completed, thus speeding up the work efficiency.

The further | heald jacquard loom beam of the loom

However, there is an obvious limitation to the use of harnesses, that is, it is impossible to weave more complex patterns, because complex patterns mean that more warp and weft yarns are needed and the warp lifting laws are more complex, which means that hundreds or thousands of weft yarns can be introduced to complete a cycle.

If harnesses were still used to control yarn hoisting, hundreds or thousands of harnesses would be required, which would be mechanically difficult to achieve, hence the harness jacquard loom.


Instead of a heald frame, the jacquard loom is designed with two layers. Each warp thread passes through the heald thread for separate control. The upper layer picks up the warp yarn to be lifted, while the lower layer picks up the warp yarn and sends the weft through the shuttle to the opening.

However, the loom usually contained thousands of weft yarns with intricate patterns, so the wise ancestors invented the flowerbook:


Simply put, the flower book stores pattern information.

In the figure, the vertical line of the pattern is connected with the heald yarn that is inserted into the warp yarn. The horizontal line stores the jacquard information of each weft introduction. When the vertical line crosses the horizontal line and covers in front of the horizontal line, it indicates that the corresponding warp yarn will be lifted.

This is sort of a code rule.

Talking “machine” | jacquard loom

The above mentioned jacquard loom was a big step forward, but it was still, as you can imagine, slow and very labor-intensive for the weaver.

Time comes to 18th century Europe. In 1725, Bucho pioneered the use of perforated paper tape to control the lifting and lowering of warp threads, thus making patterning a semi-automated task:


For the first time in history, machines could read the contents of a storage medium and act on them.

In 1790, Joseph Marie Jacquard designed a new loom based on the work of his predecessors, and finally completed the first automatic jacquard loom in 1805:


Jacquard improved the perforated paper tape into a perforated card, punched holes on the card according to the pattern pattern, and controlled the warp lifting by driving a series of mechanical motion devices through the holes. A card corresponds to the information of warp lifting during a weft insertion in the cycle. After filling insertion, the rotation of the card can be controlled by the foot pedal. Flip the next card to the working position to control the jacquard of the new filling insertion:


The Jacquard loom greatly saved time and work (fully automatic and 25 times more efficient than before), required only one worker, and was soon widely used in factory production. Jacquard was awarded the Medal of Honor by Napoleon.

The design of punched card control fabric pattern has become the germ of programming thought and a new way for the development of information technology.

Program design ideas began to bud | difference engine


Fast forward to the early 19th century, when Frenchman Chanles Badbbage designed and built the difference engine, inspired by the Jaka loom.

The story background

At the end of the 18th century, when the French government decided to adopt the decimal system in mathematics after the creation of the metric system, it tried to divide 90-degree right angles into 100 degrees and 60-second minutes into 100 seconds, which seems like a retrograde idea now, but they did. This reform brought not only people in the use of intuitive discomfort, the original production of mathematical tables (such as trigonometry tables) have to be completely reworked.

Mathematician Gaspard de Prony, who was struggling with the task, remembered The economist Adam Smith’s treatise on The Rich, He decided to use the division of labor proposed in the book and divide the tabulating workers into three groups:

  • The first group consisted of five or six brilliant mathematicians who worked out the formulas needed in their operations.
  • The second group consisted of nine or ten people who were good at math. They worked out the key numbers and simplified the formulas formulated by the first group.
  • The third group consists of about 100 calculators who use the key data and formulas provided by the second group to do the simplest addition and subtraction to arrive at the final result.

The third group’s jobs were so easy that they didn’t even know what they were doing. In fact, most of them were poorly educated, mostly hairdressers and unemployed people. It can be seen that even illiterate people could do the calculation, in those days still rely on manpower to do.

To make sure his tables were correct, Proni had to count each number at least twice, and in different places in France, in different ways. The project took ten years to complete, but unfortunately there were still mistakes in the final form. Speaking of this, it can be said that almost no version of the mathematical table at that time is completely correct, and some versions are even full of mistakes. To know that the mathematical table error sometimes has serious consequences, for example, a nautical table error may directly lead to the destruction of the ship.

Babbage, tears streaming down her face, after learned the deeds of the, is determined to do a set of completely correct mathematics with a table, for the purpose, he tried various means to reduce errors, such as adjusting the color of the paper and ink in order to improve the recognition of digital, directly take multiple versions of the existing table transcriber, than, let different personnel check it over and over again, A version was published in 1827, but it still had errors in it. As long as there is no human perfect, Babbage completely kneel, he vowed to build a machine, let the machine to produce mathematical tables.

This is the famous difference engine.

· Difference engine Design drawings & Semi-finished products:


The first computer in the true sense | analysis machine

Babbage was not discouraged by his failure to implement the difference engine, or that he simply could not stop. Babbage continued to improve on his design, knowing it would never happen, until one day he conceived of an unprecedented machine, the analytical machine, which became the first great forerunner of modern computing. (Father of computing)

When the analytical engine was conceived in 1834, Babbage himself was astounded by it. Before that, any computing machine could only do what it was programmed to do, either simple addition, subtraction, multiplication and division, or just difference arithmetic like the difference engine, which was called calculator. The analytical machine was a real computer, not limited to specific functions, but actually programmable. Can be used to calculate arbitrary functions – modern people can not imagine the experience of writing a program on a piece of gear.

Babbage’s analytical engine mainly consists of three parts:

  1. The counting apparatus for storing data, which Babbage called “stores,” the equivalent of memory in modern cpus, was partly an improvement on the counting apparatus on differential machines, and it is easy to imagine what it might look like;
  2. Babbage called the “mill”, which was the equivalent of the arithmetic unit in the CPU. This part of the structure was relatively complex. Babbage also made some optimizations for multiplication and division.
  3. Babbage did not name the device that controlled the sequence of operations, selected the data to be processed, and produced the results. Because of its barrel shape, we could call it a “control bucket,” which was obviously the equivalent of a controller in modern CPUS.

With these three components and babbage’s unneglected input and output devices, we were surprised to find that the components of the analytical engine were exactly the same as the five components required for the current von Neumann architecture!

Babbage’s other great innovation was the introduction of punched cards (punched cards) into computing machines, used to control data entry and calculation, and used in almost all digital computers from that time until the first electronic computer.


The whole analytical machine is programmed with gears and rods like this: it reads data from a data card into memory, and transfers the data from memory to an algorithm, which then passes the data back to memory.

Unfortunately, Babbage was never able to build an analytical engine, leaving behind a model machine, more than 2,000 drawings, and his last words:

“If any man, undeterred by the lessons of my life, can proceed to build himself into a machine which possesses all the power of mathematical analysis in its own right… I will yield my reputation to him unhesitatingly, for he alone can fully appreciate my efforts and the true value of their results.”

· Analytical machine Design drawings & model machine:


The advent of the era of perforated | tabulator

Since 1790, the United States has taken a census every 10 years. Over the centuries, the population exploded from less than 4 million in 1790 to more than 50 million in 1880, as populations multiplied and emigrated.

Population growth curves of the United States from 1790 to 1880

Don’t like the age of the Internet, now people born, all kinds of information is electronically, registered good, even the data mining, you can’t imagine, in the computing equipment crude basically arithmetic of the 19th century by hand, must level population statistics has become the government’s “can’t bear”.

The 10th census, which started in 1880, took 8 years to complete, that is to say, they will start the 11th census after two years of rest, and this census will take more than 10 years, I am afraid, what about the 12th and 13th census? If the statistics take more than 10 years, it becomes meaningless.

This worried the census office, which decided to invite bids from the whole society for inventions that would reduce manual labor and improve statistical efficiency. Just as opportunity is for the prepared mind, Herman Hollerith, a young Columbia graduate, stood out from the crowd with a patent he filed in 1884.


tabulator

The machine he invented was called a tabulator/ Tabulating-machine, which was, as the name suggests, a machine designed to make tabulating-in-numbers. Tabulating machine is mainly composed of indicator device, punch machine, card reading device and classification box.

Indicator device contains 4 lines, 10 columns a total of 40 indicator dial, each disk surface is evenly divided into 100 cells, and equipped with two Pointers, and watches very similar, “minute hand” turn a circle can count 100, “hour hand” turn a circle is counted 10000. It can be seen that the whole display device can express very large data.


Tabulator work is built around punch card: the operator use punch production punch card first, then use identification card information on the card reader device, the machine automatically complete statistics and real-time display on the readings as a result, in the end, will be put into the pigeon-hole a card, classified storage, statistics for next time use.

Application of punch cards

Hollerith had been waiting in line at a train station one day when his eyes fell on the puncher rattling in the inspector’s hand. He found that ticket inspectors deliberately punched holes in different parts of the ticket according to the gender and age of the passenger. As more people were tested, he confirmed the pattern. An idea struck him: a bigger card with more places to punch could be used to indicate more identity information, including nationality, race, gender, date of birth and so on.

This is the punch card used in the 1890 census, a card that records information about a resident. The card was designed to be about 18.73cm long and 8.26cm wide, the exact size of a U.S. dollar bill at the time, because Hollerith used Treasury boxes to hold the cards.


The cards had more than 300 holes, and like Jacquard and Babbage, information was represented by whether or not each hole was punched. Although this form has a bit of a binary feel to it, the design at the time was far from mature enough to make use of the true value of binary. For example, we now usually use one-digit data to indicate gender, such as 1 for male and 0 for female, but Hollerith used two holes on the card, indicating that men punched in one place and women punched in the other. In fact, gender is ok, but it is much more wasteful when representing dates. Twelve months requires 12 holes, compared with four for conventional binary code. Of course, this limitation is also related to the simple circuit implementation in the tabulator.

Careful readers may find that the lower right corner of the card is cut off, which is not incomplete, but specially designed to avoid putting, and the current TWO-DIMENSIONAL code has only three corners is the same reason.

This kind of practical detail design works even better on punches. Below is an operator using a puncher to punch a card. Instead of laboring to find holes in the card, she punches directly against the wider-spaced panel, where a lever matches the two. The operation panel is also made into an arc, quite a point today’s ergonomic keyboard style.


In tabulating machines, punched cards (or paper tape) were used to store instructions rather than data. More representative, one is jacquard jacquard machine, with punched cards to control the warp lifting; The second is the automatic piano, with perforated paper tape control key press. In The US TV series Westworld, each story cycle begins with a close-up of a pianola playing the seemingly peaceful but actually bizarre background music.

It was Hollerith who introduced punched cards as a data storage medium and ushered in a new era of data processing. Hollerith cards came to be known as Hollerith cards. Punched cards and punched tape dominated computing for a century as input and output carriers.

Unit recording age

With the efficient operation of tabulating machines, the census of 1890 took only six years. In 1896, Hollerith set up The Tabulating Machine Company and kept improving his product, The census has been conducted in cooperation with Britain, Italy, Germany, Russia, Australia, Canada, France, Norway, Puerto Rico, Cuba, the Philippines and other countries and regions.

By 1914, the Tabulating Company was producing as many as two million punch cards a day. It didn’t take long for some competitors to rise and history ushered in a flourishing era of data processing. Their products are no longer limited to the census, and gradually expand to accounting, inventory management and other fields that also need to deal with big data. These machines are collectively known as Unit Record equipment, the descendants of tabulating machines.

Around the punch card business card printing, card reading, data processing and card classification is their standard function, puncher, card reader, classifier is their standard configuration. These components became increasingly automated, as manual card readers were quickly replaced by automatic ones, gradually increasing the reading speed from 100 cards per minute to 2,000. With the improvement of identification accuracy, the hole spacing of cards is becoming smaller and smaller. Cards with 80 ~ 90 rows of holes have become the mainstream, and some cards even have as many as 130 rows of holes.

The typical 80 series punch card of the 20th century

The function of the machine is also gradually stronger, no longer simply counting the number of perforations, subtraction, multiplication and other operations have emerged. In 1928, scientists at Columbia University went so far as to calculate the orbit of the moon using cell recording equipment that they punched 20 million holes in half a million cards, demonstrating the limitless potential of cell recording equipment.

Machine circuit implementations are becoming more complex, but also more versatile. The circuit of the tabulating machine used in 1890 was fixed, and it was very troublesome to transform it in the face of new statistical tasks.

In 1906 Hollerith introduced plugboards — boards filled with conductive holes that changed the logic of a circuit by changing the position of the pins on the board. Imagine, the interior of the lug plate has good cloth line with a variety of functions, but they are in the off state, each connected to a two holes on the lug plate, like a family to feed the birds grow up with the mouth, external wire like delicious worm, head and tail respectively when the insects and birds beaks and beak contact, line is conduction, The little bird went to work. In this way, different birds can be activated each time they are used to complete different tasks. This is already a demonstration of programmability.


In 1911, the Tabulating Company merged with three other companies to form CTR (Computing-Tabulating-Recording Company), and the Tabulating Company continued to operate as a subsidiary Company until 1933.

In 1924, CTR changed its name to International Business Machines Corporation, now known as IBM. IT can be seen that among many young IT companies today, IBM, with a history of 100 years, is a worthy predecessor, which has completely participated in and witnessed the development history of the whole modern computer. IBM remained the tabulating company’s leader in the cell record market, producing 72.5 million punch cards a day by 1955.

Beginning in 1937, cell recording equipment became increasingly electronic, blurring the line with electronic computers and eventually giving way to them. The short-lived era of cell recording came to an end in 1976 when IBM’s core cell recording product, the IBM Model I, was discontinued. It seemed like a rehearsal for the coming of electronic computing, and many of the designs were still used, such as punch cards and plug boards.

It is interesting to note that even with the increasing popularity of electronic computers, many organizations have become so accustomed to the use of unit recording equipment that they have been reluctant to replace it, and a few organizations have been using it well into the 21st century.

In one sentence

Programming can help us solve some very practical problems in a very cool way.


You can also expand on this: Lines of Code that Changed the World

Part 2. The principle of binary and CPU | the wisdom of the contain in coding


  • Learn MoreThanJava about binary and how cpus work

So this is how we count

Before we talk about “binary” and “how cpus work,” let’s talk about the most mundane numbers in our lives, which we deal with a lot: an agreed time, the price of an item, a person’s height…. Few people have thought much about how these numbers are expressed. Why do you take it for granted that 1024 means “one thousand and twenty-four” and not something else?

Perhaps you have never thought, in this simple number, precipitation of human wisdom.

One base counting method

Long before the concept of numbers, humans learned to use sticks, stones, seashells and other small objects found everywhere in nature to indicate the number of prey, fruits, and tribal populations. For example, if you make a pile of stones in a corner, throw one stone into it for every one you hit, and take two stones from each one you eat. They didn’t care about the total number of stones, they just looked at it from time to time and knew it.

In fact, this is the simplest form of notation, which mathematicians call the unary numeral system. Let’s symbolise it, for example with a slash / :

  • 1is/;
  • 2is//;
  • 4is////;

It doesn’t seem to be a problem. That’s how we count our fingers, but when the numbers are big, things get out of hand.

Additive notation of character values

To solve the problem of recording large numbers, we had to invent other symbols for larger numbers, such as a bar – for 10 and a cross + for 100. So:

  • 16is-//////;
  • 32is---//;
  • 128is+--////////;

The beautiful… This method of representing numbers by notation type and number is called sign-value notation, and it was used by both ancient Egypt and Ancient Rome, with different notation.

Ancient Egyptian numeration symbols:

1 10 100 1000 10000 100000 1000000

1024 In ancient Egypt it was written:


One of the great advantages of additive notation, as you will see, is that symbols can be arbitrarily shuffled without affecting the meaning of the numbers. Chinese Tibetans used stones to represent 1, sticks to represent 10, fruit stones to represent 100, broad beans to represent 1000, and tiles to represent 10000. Then, when you hold a broad bean, two sticks and four stones in your hand at random, others still know that they are 1024.

The Ancient Romans did things a little differently, and they had a penchant for pentadecimal:

1 5 10 50 100 500 1000
I V X L C D M

These symbols are still in use today, and many clocks and watches still use Roman numerals: I, II, III, IV, V, VI, VII, VIII, IX, X, XI, and XII. You will find that the Roman notation is a variant of the summation notation, because it does not just add, it subtracts. This way you don’t allow the symbols to be out of order, so IV and VI are different numbers.

So why did the Romans bother with this more complicated notation? Just for reading and writing convenience. Again, 9, IX is more compact than VIIII.

There’s actually a better way to do it — to write the number of symbols in a different list. For example, A for one symbol, B for two symbols, and so on, I for nine symbols.

++—–////// +E-F/ You must be wondering where this is convenient. It’s just that we’re so used to it that we don’t notice it.

In Chinese, number, ten and hundred replace /, – and +, while one, two and three replace A, B and C. 256 is two hundred fifty-six, which is cumbersome, and we usually omit it.

In fact, like Japanese, English is also used in this notation, concise, elegant.

The fly in the ointment is that this form is easy to read and write, but not easy to calculate. Ancient Chinese people set up a wide stage for classical arithmetic tools such as calculators and abacus, but left no room for written arithmetic. Imagine if you had to write these characters on scratch paper in vertical rows, your heart must be very uncomfortable.

Digit system of notation

In the 5th century, The Indian mathematician Aryabhata (476-550) created the now widely used positional notation/place-value notation, whose main notation, It is the Same Indian invention of Arabic numerals: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.

1, 2, 3 replace A, B, C, and /, -, +? Is represented by the position of Arabic numerals. As you know, the right-most bit is equal to /, and the subright-most bit is equal to -. By the value of each position to represent the number, so the name value system.

Serious mathematicians highly generalize the nature of bite-value notation in a polynomial that, in decimal, looks like this:



This is an n-digit decimal number, where ai is the ith digit. Let’s look at 1024 as an example:


Since we are familiar with the decimal system, this painstaking expansion may make you laugh, but the value of this polynomial becomes apparent when we generalize it to other bases. The bit-value representation of n-bit b-base numbers:



What is 1024 in binary?


Thus, 1024 binary is written as 10000000000.

In addition to the most common decimal system and the binary system in the computer, there are common base seven (such as a week 7 days), decimal (such as 1 year 12 months), hexadecimal (such as ancient 1 jin 16 taels), sixty decimal (such as sixty sub), etc., as long as it makes sense, any base system can be used for you.

Why use binary

At this point, you may not be so unfamiliar with “binary”, it is just a number system.

But why does it have to be binary? Is it bad to use the decimal system that humans are used to?

Reason 1: It’s physically easy to implement

Computers work on electricity, which means that digital signals need to be mapped to electrical signals. The simplest way to do this is:

  • 0 – No electricity (0 V)
  • 1 – a little bit (5 V)

Binary is technically the easiest to implement. This is because there are many physical devices with two stable states, such as gate circuit on and off, high and low voltage, and they just can correspond to represent “1” and “0” these two digits. If you use decimal, you have to make a physical circuit with 10 stable states, which is very difficult.

Reason 2: The machine has high reliability

Why is using more complex number systems a problem?

Assuming we use a ternary (3-digit) digital system involving a computer, if we have a voltage from 0 V to 5 V, then we can do the following mapping:

  • 0 – 0 V;
  • 1-2.5 V.
  • 2 – 5 V;

  • Image source: https://pmihaylov.com/intro-binary-numbers/

Seems reasonable? But imagine that I send a number at 2.5V. But because of some noise in the circuit, I get 2.3V at the output, so I treat it as 0. The result is?

Someone sent me a 1, but I treated it as a 0. Data loss is a very serious problem.

The use of binary is much more reliable, because the voltage is high and low, current and no and so on are a qualitative change, two physical state is stable, clear, therefore, binary code transmission of anti-interference ability, high reliability of identification information.

Why do computer systems have to have clocks


  • Image source: http://programmedlessons.org/Java9/chap02/ch02_11.html

The purpose of the digital system is to test on/off (binary) values only at certain points in time, which gives the wire (or other equipment) time to replace. That’s why computer systems have clocks.

The clock periodically measures the signal, and T1 and T2 are the time points at which the signal can be measured.

Clocks use all these points of time to keep in sync. The faster clock means that the wires can be tested more times per second, and the whole system runs faster. The 2 GHz processor checks binary values 2 billion times per second. Between these times, the allowable values change and stabilize. The faster the processor chip, the more tests can be done per second and the more decisions can be made per second.

Reason 3: The calculation rules are simple

It has been proved by mathematical derivation that there are N(N+1)/2 rules for the arithmetic summation or quadrature of n-base numbers. If using decimal, then N=10, there are 55 summation or quadrature operation rules; With binary, N=2, there are only three summation or quadrature rules, taking the addition mentioned above as an example:

0+0=0, 0+1=1, 1+1=10Copy the code

Therefore, it can greatly simplify the design of physical devices such as arithmetic devices.

Reason 4: Logical judgment is convenient

After adopting binary, the only two symbols “1” and “0” can correspond to the two values “true” and “false” of the logical proposition, which can be conveniently used to analyze and design the logic circuit of the computer with logical algebra, a powerful tool.

More efficient ternary computers were built in the 1950s, but the trade-off between efficiency and complexity was never matched by binary. Binary is still around in today’s world.

A simple demonstration of how the CPU actually works

As we have seen above, computers operate in binary form. They have only two states: on (1) and off (0). To perform binary computation, we need to use a special electronic device called a transistor. For the moment, let’s think of it as a kind of switch that opens when the current is on and closes when no current is on.

Use “switch” to build logic circuit

We know that when you plug in a light, it lights up:


So, with a switch, we can build a basic and or door.

With the door


The logic of the circuit is: only when A and B are on at the same time, the LED light will be on, that is, we can use electrical signals to simply simulate:

A B Y
0 0 0
1 0 0
0 1 0
1 1 1

Or gate


The logic of the circuit is: when A or B is on, the LED light will be on, that is, the output 1 is considered, we can use electrical signals to simply simulate:

A B Y
0 0 0
1 0 1
0 1 1
1 1 1

The other door

Similarly, we can use more electronic components to create the basic seven logic gates:


  • Photo: https://www.zhihu.com/question/348237008/answer/843382847 | @ Zign

Need special mention here xor gate, we need to know that there is a kind of electronic components can use to input from the electrical properties, which means the input 1, 0, 0, 1 output, then we can simulate the simple xor gate logic circuit (actual will become more complicated, here only show exclusive or) :


A’ and B’ represent the inverse values of switches A and B respectively. From the figure, it is easy to know that only when there is only one input 1 in A and B, the whole circuit will output 1.

Make a simple adder demonstration using logic gates

OK, now that we have seen that we can use “switches” to simulate logical operations, let’s try to reproduce how a simple addition operator works:


Basic binary addition can be done with only two gates. The figure above is A half-adder created by using logic.ly. A and B are the two numbers that enable us to calculate, and the last one is our digital display chip. Its function is to display the numbers according to the input. This is usually called) corresponds to input 20=1, 21=2, 22=4, 23=8, and displays 0 without any input. If pin 1 has input as shown above, it displays 0 + 1= 1.

Let’s understand the circuit at the top:

  • If only one input is open, but not both, then the XOR gate (XOR gate) here opens, corresponding to the inputPin 1To showThe number 1(similar to the1 plus 0 and 0 plus 1);
  • If both inputs are open, the AND gate (AND gate) opens, corresponding to the inputPin 2To showThe number 2(similar to the1 + 1);
  • If there is no input, both the AND gate AND the XOR gate remain closed AND are displayed0(similar to the0 + 0);

Therefore, if both are open, XOR remains closed AND the AND door is open, giving the correct answer 2:


But this is only the most basic semi-additive operator, not very useful, because it can only solve one of the simplest mathematical problems. But if we concatenate both of them with another input, we get a complete adder:


If you think about it a few times, you’ll see that this three-input adder can already add up to three binary digits. In the same way, we can make this adder add up to more numbers by connecting more carries, which of course means a longer chain.

Most other mathematical operations can be done by addition. Multiplication is just repeated addition, subtraction can be done by some fancy bit inversion, and division is just repeated subtraction. And, although all modern computers have hardware-based solutions to speed up more complex operations, technically you can do it all with a full adder.

In one sentence

Coding is a process of exploration and learning that, if we want to, can provide much of the same pleasure as solving a mathematical problem.


Part 3. The machine instructions to high-level language | standing on the precursor to the shoulders of giants


  • “MoreThanJava” machine instructions to assembly to high-level programming languages

Machine instructions

We’ve learned the basics of binary and the CPU, that as programs run, the CPU oscillates its clock hundreds of millions, billions, billions of times a second, performing tiny “electronic operations” in sync, such as reading a byte of data from memory to the CPU or determining whether a byte is a 0 or a 1.

The CPU itself has a defined set of “basic actions” (called machine instructions) that can be performed:

  1. Read instruction; 2. Execute instructions; 3. Write register;

That’s pretty much all the CPU does. These actions can only be performed once at a time, but they can be performed billions of times per second, and this order of magnitude of “small actions” adds up to a large “useful action.”

Everything the processor does is based on these tiny operations! Fortunately, we no longer need to know the details of these operations to write and use programs. The purpose of “high-level languages” such as Java is to organize these small electronic operations into large useful units expressed in human-readable “programming languages”.

Although machine language is a bit anti-human, at least we can use it to write code. For example:

00000001 00000010 00000001

00000100 00000100 00000000

Copy the code

It seems that this section of code is a bit confusing and unreadable.

So you can feel the programmers of the last century using punched cards:


Use paper tape:


Or even directly plug and unplug the line or press the switch:


What a hardcore thing…

Assembly language

PU instructions are binary, which is obviously unreadable to humans. To solve the readability problem of binary instructions, engineers wrote those instructions in octal. Binary to octal is easy, but octal is not readable either.

Naturally, the final word is written as ADD. Memory addresses are no longer referenced directly, but are represented by labels.

The levitator is one more step to translate the verbal instruction into binary, and the program that does it is called assembler. The text it processes is, of course, called Aseembly code. After standardization, it is called Assembly Language, abbreviated as ASM, and translated into Assembly language in Chinese.

Assembly language demo

To take a simple example, we need to calculate:

1 plus 4 times 2 plus 3Copy the code

Let’s do the conversion according to “postfix notation” :

1,4, + 2, *, 3, +Copy the code

The method we usually use is “infix notation”, which puts the computational symbol in the middle, such as 1 + 3, and the suffix, which puts the symbol at the end, such as 1, 3, +.

The nice thing about this is that you don’t have to multiply, divide, add or subtract, you don’t have parentheses, you just do it. (For example, 1, 3, +, I’m going to save 1 and 3 and when I see + I know it’s addition, I’m going to add)

OK, let’s start from the beginning using assembly language to write the program, first step: save 1 (put into register) :

MOV  1
Copy the code

And then it’s 4, plus, so just add it:

ADD 4
Copy the code

SHL means to move one bit to the left. In binary, moving one unit to the left is the same as multiplying by two. For example, 01 means 1 and 10 means 2.

SHL 0
Copy the code

And finally, 3, +, plus:

ADD 3
Copy the code

The complete procedure is as follows:

MOV  1
ADD  4
SHL  0
ADD  3
Copy the code

This seems a lot better than a binary like 00001111! Programmers were moved to tears:


A high-level language

Moving away from binary, we have assembly language that is more readable, but still tedious and complex. Each assembly instruction represents A basic operation, such as: “Get A number from memory location X and put it in register A”, “add A number in register A to A number in register B”. This style of programming is time-consuming and error-prone, and errors are hard to spot.

For example, take a look at the BAILOUT code used by Apollo 11 in 1969 to prevent the lunar module computer from running out of resources:

POODOO    INHINT
    CA  Q
    TS  ALMCADR
TC  BANKCALL
CADR  VAC5STOR  # STORE ERASABLES FOR DEBUGGING PURPOSES.

INDEX  ALMCADR
CAF  0
Copy the code

ABORT2 TC BORTENT

OCT77770 OCT 77770 # DONT MOVE CA V37FLBIT # IS AVERAGE G ON MASK FLAGWRD7 CCS A TC WHIMPER -1 # YES. DONT DO POODOO. DO BAILOUT.

TC  DOWNFLAG
ADRES  STATEFLG

TC  DOWNFLAG
ADRES  REINTFLG

TC  DOWNFLAG
ADRES  NODOFLAG

TC  BANKCALL
CADR  MR.KLEAN
TC  WHIMPER
Copy the code

Copy the code

  • Reference: lines of code – https://www.infoq.cn/article/5CaYH8NbS6BmptWKRgkX to change the world

Doesn’t seem to be easy to read…

The source code for the Apollo moon mission is available on Github, and those interested can check it out below (to get a feel for the engineering capabilities of the programmers at the time) :

  • https://github.com/chrislgarry/Apollo-11

Also, Margaret Heafield Hamilton (female programmer), who was in charge of the design of the code at the time, and the amount of code that was completed as tall as a person:

The first high-level language: FORTRAN

When John Backus joined IBM in 1950 as a scientific programmer, it was already possible to write programs using mnemonics like ADD, our assembly language, instead of numeric code. This makes programming easier, but even a simple program requires dozens of operations and is still hard to find.

Backus thought it should be possible to create a programming language in which a series of calculations could be expressed in a form similar to mathematical notation. This can then be converted into digital code that a computer can understand using a specific translator (or compiler, in today’s terminology).

Backus proposed the idea to his manager in 1953. He was given a budget and encouraged to hire a small team to test the idea. Three years later, the team released a manual describing the IBM Mathematical Formula Translating System, or FORTRAN. Soon after, IBM made the first FORTRAN compiler available to IBM 704 users.

The father of FORTRAN,

Backus and his team created the world’s first high-level programming language. Scientists and engineers would no longer need to write their programs as numerical code or lengthy mnemonics.

FORTRAN code demo

Here is an example of code that calculates and prints 8 * 6:

program VF0944
implicit none

integer a, b, c a= 8 b= 6 c= a*b

Copy the code

print *, 'Hello World, a, b, c= ', a, b, c end program VF0944

Doesn’t it look much cleaner (human-readable) than assembly code?

The significance of FORTRAN,

The advent of FORTRAN has an epoch-making significance in the history of computer. It makes the computer language come out from the original low-level assembly language and enter a higher realm. The computer language is no longer the patent of computer experts, and the vast number of engineers and technicians have the means of computer programming.

This computer faster deep into the society, its budding in the industrial sector, especially in the rocket, missile, the design of the artificial earth satellite expert, so some say FORTRAN language of industrial application of the computer as possible, is to promote economic recovery after the second world war, the western industry and into the invisible powers of the second industrial revolution, It’s an invisible steam engine.

In one sentence

Computer pioneers have set up the computer world for us, standing on the shoulders of the pioneers, we can now easily see higher and further.


Part 4. Building your Own Application (World)


  • Photo from: https://www.infoq.cn/article/5CaYH8NbS6BmptWKRgkX

There are many joys of coding, and one of them is putting your ideas into practice.

For example, the user needs to keep clicking the mouse to play the game, so he wrote a mouse link device:


For example, write a dating website for your beloved girl:


For example, add a reinforcement learning algorithm to FlappyBird and let it learn how to fly by itself :(the picture shows 4527 steps on its own)


For example, netizens write their own classical Chinese language :(use classical Chinese to write codes)

// HelloWorld program demo

I have a number. Yue three. The name is "A".

For is "a" times.

I have a word. "Ask for the good news of heaven and earth." . Of the book.

At such a time.

Copy the code

Run output:

Ask heaven and earth.

Ask heaven and earth.

Ask heaven and earth.

Copy the code

In one sentence

We can put a lot of our ideas into practice programmatically (as long as we keep exploring and learning) and have a lot of fun as we meet the challenges and implement them.


A small summary

Overall, IT is exciting.

There is a saying that “software eats the world”. We are also living in a world dominated by computers.

And programming is not a skill that everyone has. With technology, everything is possible, and the Internet age now offers more opportunities than ever to learn and create “your own world.”


  • Github: More Than Java: More Than Code star: github.com/wmyskxz/Mor…
  • Personal public number: wmyskxz, personal independent domain name blog: wmyskxz.com, adhere to the original output, below the scan code concern, 2020, and you grow together!

Thank you very much for reading this, if you think this article is well written, if you think there is something about “I don’t have three hearts”, please like, follow, share and leave a comment!

Creation is not easy, your support and recognition, is the biggest motivation for my creation, we will see you in the next article!