Fundamentals of Computing System (2)

Fundamentals of Computing System (2)

If the knowledge points in the book "Computer System Fundamentals" are roughly divided, they can be divided into C language and the bottom part. The basic grammar of the c language can be learned and consolidated through various online videos, which will not be repeated in this article. Therefore, we will focus on the exploration and understanding of the bottom layer . Next, we will introduce the most basic "pinyin" grammar of computers: binary.

1. Why use binary?

In the previous article, we explained that: 1 and 0 can accurately represent the circuit state of the computer. But if you want to accurately describe the reason, it is not just because of the expression of the circuit. More importantly, it is the unified management of computer expression and storage methods. We use bits to represent the smallest unit of information storage. Each bit can only be 1 or 0. If many bits are grouped together, it can be used to represent different information. For example, if 8 bits are combined together, it can represent 256 (2^8 ) Kinds of different numbers, if artificially specified, we can use these 256 situations to represent 256 different pieces of information. Let's start with the most basic, binary integers that the university has been exposed to before.

Two, integer binary

1. Unsigned binary number

Regardless of the sign for the time being, there can only be 0 or 1 in one bit, then the number starting from 2 should be expressed as: 10, 11, 100, 101... If the unified specification is 8 bits, 30 is 00011110, and you can do it yourself Derive.

2. After adding the symbol...

In the actual operation, a large number of negative numbers are needed, so how to represent negative numbers? The first method that I came up with is to use the first bit as a sign to represent the bit, such as 0100 for 4, then we use 1100 for -4 . We call this representation method the original code . In addition to the original code, some people think that we can invert all the binary sequences of the original positive numbers (or bitwise inversion), that is, use 1011 to represent -4. This method is called an inverted code .

However, the above two methods have a fatal flaw. They are suitable for the human brain and not for computers. When we are performing calculations, we can translate the negative numbers of the original code in our brains and perform the calculations again, but this process is not for the computer. Extremely difficult.

Therefore, we need to find a storage method, which must meet: 1. Easy to be understood by the human brain 2. Easy to calculate by computer

After all, people have found a binary representation that perfectly fits these two requirements, which we call the complement .

The expression of the positive number of complement is similar to others, such as 5 for 0101

But -5 is represented as 1011. Similarly, -10 is represented as 10110, -16 is represented as 10000... It is not difficult to find that the negative number of the complement has a great feature that they are added to the original positive number to get 0. This will be extremely helpful for the computer to calculate the data.

For us, the form of complement code seems difficult to understand. But the predecessors have summed up the law for us: the opposite number can be obtained by negating the bit and adding one . With this rule, the logic of the human brain can easily understand the complement. Therefore, the complement code has become a common data form in today's computers.

Three, decimal binary

In the computer, we call the data of the "decimal number" type the floating point type. To facilitate storage, we use a storage mechanism similar to scientific notation. For example, 5.0 in decimal, 101.0 in binary, is equivalent to 1.01*2^2. Continuing this idea, IEEE (International Institute of Electrical and Electronics Engineers) stipulates:

Fundamentals of Computing System (2)

Let's take the float type single-precision floating-point number in C language as an example. For a 32-bit floating-point number, the highest bit is s, which means 0 is positive and 1 negative. The next 8-bit exponent is E, and the remaining 23 bits are significant digits. M.

There is only one S, which is easy to understand. But for M and E, there are special regulations:

For example, M represents the decimal part of 1.01011*2^9. IEEE 754 stipulates that when saving M in the computer, the default first digit is always 1, and only the following 01011 part is saved. This can save a significant number, so that only 23 bits of M can store 24 bits of information.

As for the situation of E, it is quite special.

E is not only an unsigned integer, but also has special rules. E has a total of 8 bits, because it is unsigned, the value range is 0~255. But in order to get the negative number in scientific notation, IEEE has stipulated an intermediate number: 127. The value of E must be subtracted from 127 to represent the original data type. For 1.01011*2^9, it must be saved as 9+127=136, which is 10001010.

However, there are special cases: E is all 1 or all 0. When E is all 0, treat E as the true value and the first number omitted from M is set to 0. This can represent some decimals very close to 0, such as 0.000000001

When E is all 1, if the significant digits M are all 0, it means positive/negative infinity.

Four, binary and hexadecimal

Because the binary representation is cumbersome and difficult to understand, we generally use hexadecimal to simplify the representation of binary. Every four-digit binary pair is equal to a hexadecimal number: this is because four-digit binary can represent 0~15, which exactly corresponds to 0~F in hexadecimal. After the hexadecimal is expressed as binary, go Consider situations such as complements or floating point numbers.

Five, other

In the binary chapter, in addition to the above, the book "Computer System Fundamentals" also proposes in detail the conversion methods of binary and decimal, decimal to binary and hexadecimal, and more important but easy to understand Boolean algebra operations , This article only lists the important and difficult points in the book, and hopes to bring you some help and thinking on the understanding of binary.

Guess you like

Origin blog.51cto.com/14930847/2615151