Chapter 548: Tech Nerd

readx;

One chapter today, one tomorrow. Pen % fun % Pavilion www.biquge.info

========

Every inch of space around him seemed to be stacked with all kinds of electronic devices and components, dimly lit and crowded, Lin Hong felt as if he had come to the electronics market in the City God's Temple in a city on the mainland.

After walking for a while, he saw that there were more and more electronic accessories and components related to computers.

In the front, a young man with yellow bangs on his forehead is playing a computer game in the store.

At this time, Huang Yue, who was walking in front, suddenly stopped, he turned his head to Guang Yongyuan and said, "According to the old rules." ”

When he was done, he walked alone and walked forward.

"The old rules?" Lin Hong glanced at Guang Yongyuan with puzzled eyes.

Guang Yongyuan had no choice but to explain: "If you want to enter this circle, you must prove that your skills have reached this level. Although they all know me, they are all brainless, and they only recognize technology and not people. ”

After going around and around, Lin Hong finally understood that if he wanted to continue to move forward, he had to pass the test set by them, which was quite a bit of a breakthrough.

"Interesting." Lin Hong smiled, didn't care about this, and asked, "What are the projects?" ”

Guang Yongyuan said: "Programming, cracking and network infiltration. Of course, you don't have to pass all of them, as long as you can get their approval. You're fine, it's just a formality. ”

Guang Yongyuan has already seen Lin Hong's cracking technology, and even Lin Hong, a difficult bone like "Invincible Heroes", can be solved without much effort, let alone their entry test?

At this time, the dyed young man who was playing the game before had already quit the game, he shook the yellow hair on his forehead, and said to Lin Hong: "Please." ”

The first level, programming.

Lin Hong didn't have any nonsense, and sat in the seat of the young man just now, and he saw that a question had already appeared on the monitor. Obviously, they are very familiar with this kind of thing and have their own set of test procedures.

The title for Lin Hong is "Use basic operations to write the most efficient square root function you can implement".

The square root is a very important and very complex operation in mathematics, and it is usually difficult to implement this function in a computer, so programming languages generally encapsulate these functions. Very few people will understand how the bottom layer is realized.

Moreover, it is one thing to be able to achieve it, and whether it can be efficient in computing is another aspect.

The efficiency of the program is often an important difference between a master and a rookie, a real hacker, when programming. It is not only about the implementation of functions, but also about the pursuit of maximum efficiency, and sometimes it may be just a change in symbols, and its execution efficiency can be very different.

The difference between doing it once may not be noticeable, but what if you cycle it a thousand times, ten thousand times?

In order to write efficient and elegant programs, you must have an understanding of the essence of programming languages and computers. At the same time, you have to have a lot of programming experience, and you can't fake it, practice is the only way to improve your own strength.

Lin Hong knows that there is an algorithm called Newton's iterative method for finding square roots, and its principle is:

If a number is x, assume its square root is y,

If the sum of the squares of y is greater than a given error, the next value is assumed and so on until a value within the allowable error is finally obtained.

As for how to assume this value. The way to do this is to average it. Division and multiplication must be used several times.

In computers, the essence of it is addition. The operation of the whole CPU is actually an adder, when Lin Hong realized the superbrain CPU structure, it was based on an adder structure, as for the subsequent subtraction, multiplication and division operations, they are all derived from this adder.

Directly use Newton's iterative method to find the square root, this is the practice of ordinary people, Lin Hong doesn't need to think about it, if it is really implemented in this way, it is obviously impossible to pass.

Lin Hong had a clue after a little thought, he checked the compiler in the computer, and found that this computer was very well prepared, not only some common programming language compilers on the market, such as C,

AISC, Java, C++ and even some very niche programming languages such as ADA,

Lue, Lisp, and so on.

In the end, Lin Hong still called up the C language compiler in the computer and typed the code directly.

There was a thunderbolt, and only twenty seconds later, Lin Hong finished writing the function.

He called and executed it with a function, and the program ran successfully, without any errors, and passed at the first time.

After thinking about it, he deleted the two lines again and merged the two steps into one, resulting in a total of exactly ten lines of function code.

"Alright." Lin Hongdao.

Guang Yongyuan, who was standing behind him, was still frowning at the moment and looking at his program.

He couldn't figure out why Lin Hong wrote it like this.

"It's okay so soon?" The young man with dyed hair was a little surprised.

Just when he gave up his seat, he took out a handheld game console from a corner and started playing, but just now when he started playing, he heard Lin Hong say that it was OK.

This is the first time among the many challengers.

The young man with dyed hair leaned over and took a look, his face was slightly stunned, although he could understand most of the ten lines of code written by Lin Hong, there were still a few details that he didn't understand for a while.

He easily added Lin Hong's function to the time statistics macro, and after executing it 10,000 times, the time was finally displayed, 965 milliseconds, that is, less than one second.

He looked at Lin Hong with respectful eyes and said, "You have passed." I've been here for two years, and in the past two years, no less than 50 people have walked through here, but never one of them has done your step, not only with the accuracy of the results, but also in less than a second for 10,000 executions. ”

Lin Hong smiled, there is nothing to be proud of his praise, these are the most basic things, as long as you understand the operation of the CPU, you should basically be able to achieve it if you think about it more, there is nothing to be proud of.

Guang Yongyuan asked at this time: "Ah Hong, I don't understand very well, doesn't I use the binary search method to find the square root?" ”

Guang Yongyuan is not what he is best at, after all, he is from a wild road, and the basic part is not very solid, Lin Hong's ten lines of code, he was confused.

The dichotomous search he refers to is actually one of the ways to implement the iterative method of the Bulls.

Lin Hong nodded: "The algorithm is indeed this, but here, I use binary shifts instead of multiplication and division." You see......"

Lin Hong saw that he didn't understand very well, so he re-called the compiler, lowered the breakpoint, tracked the memory assignment of the variable, and explained while operating:

"At the binary level, from front to back to decide whether each binary bit is 0 or 1, therefore, we can go from the highest bit to the lowest bit, in turn up to 1, to see if the product result is greater than the target number, if it is greater than the target number, that bit will keep 0, in this case, we don't really need to calculate the multiplication on 1, but on the previous result, plus the number before 1 to move the position of 1 to the left so many bits twice as many bits, plus the position of the previous 1 to the left to move the position of the previous 1 to the position of the previous 1 ......"

After Lin Hong's demonstration and explanation, Guang Yongyuan suddenly realized, and the young man behind him also nodded with relief, although he knew the general principle, but there were still some places that he did not understand in terms of details, and after listening to Lin Hong's complete explanation, it became clear.

In other words, the entire algorithm Lin Hong uses binary-level operations, and it is difficult to think about it quickly, or in other words, no program can be faster than his algorithm.

It only took about twenty seconds to complete the first level, and the answers were so good that I had never encountered them before.

Lin Hong originally wanted to see what the problem was behind, but after Huang Yue saw Lin Hong's procedure, he directly announced that Lin Hong had passed the test, and there was no need to continue to break through.

This question was actually given by Huang Yue himself, and he gave a standard answer at the beginning, which was also an implementation at the binary level, but there was still a considerable gap between the two.

Although this is the most basic thing, it is these things that can see a person's level the most.

Obviously, Lin Hong is stronger than Huang Yue in this regard, not to mention, Guang Yongyuan told him before that Lin Hong is still a master of cracking.

In the end, Lin Hong successfully entered their base camp, which was a rather large hall, but there, with ten computers and servers of various brands, it looked a little crowded.

There were a lot of young people in the hall, and when they saw the new members, some applauded, some whistled to welcome, but that's all, after the usual welcome ceremony, they once again focused on their computer monitors.

Huang Yue focused on introducing two people to Lin Hong, one is called Yuan Lebang, a fat man who is so fat that he can't even bend his waist, with a smiling face like Maitreya Buddha, and his field of expertise is game cracking, and the person Guang Yongyuan wants to dig up the most is him.

The other is Ruan Feizhou, with thick black-rimmed glasses, he specializes in hardware hacking, and on his desk, there are all kinds of electronic components and the latest game consoles, including Sony's PS game console and Nintendo's G

A and NDS series consoles.

In Ruan Feizhou's body, Lin Hong saw Gu Wei's shadow.

They are not a company, not even a team, they just gather together based on interest, Huang Yue provides them with a place for free, and this is Apliu Street, where any electrical appliances and components can be easily found.

They're a bunch of technophiles who are crazy about technology.