Basic knowledge of C Language

Source: Internet
Author: User
Tags arabic numbers

This is the first chapter of my C language textbook. It consists of two parts: Computer composition and working principle, and information digitization. if you have any shortcomings, you can add them or make some suggestions.

 

Chapter 1 storage of computers and data section 1 it is a strange thing to know about computers. Currently, the C language textbooks are variables, expressions, and computer principles, the C language is used as a language and mathematics, but it is hard to list some grammar rules. The students are hard to understand, so they have to remember what they want, in fact, C language is a very studious language. The core syntax rules are very few and are closely related to computers. Therefore, you must learn the basics of computers, mastering Basic computer knowledge is vital to learning C language and will be extremely beneficial to programming in other languages in the future. C language also has the advantage of being concise and clear in writing, and C ++, Java, C #, JavaScript and other languages have very similar writing methods, so learning C language well can easily transition to a large number of other programming languages. After talking about C, Java, C #, C ++, JavaScript, Ruby, Python and so on will be released one after another, but all of them are based on this tutorial. Therefore, C language is the foundation, to learn programming, we strongly recommend that you start with C language. Next we will start to learn about computers. According to Von noriman's theory, a computer consists of five parts: a browser, a controller, a memory, an input device, and an output device. Now we usually combine the memory, Controller, and CPU (central processor). Memory is what we call Memory and hard disk, and the input device is the mouse and keyboard, the output devices mainly include displays, printers, and mappers. Where CPUAnd MemoryThe most important thing is that the CPU is the execution CommandMemory is a continuous storage unit used to store Commands and DataEach unit can store 8-bit binary numbers, also known as one BytesThe memory in the computer is measured in bytes. when describing the network speed, the memory is usually measured in bits. Pay attention to the difference. The commands to be executed by the CPU are stored in the memory, and the CPU continuously executes the commands in the memory in the specified order. This is the basic working principle of the Von noriman system. What is an instruction?Is the number of binary data. For example, 10010001 is an addition command, and 10011011 is a storage command. Different operations are performed when the CPU encounters different commands, the commands that can be executed by the CPU are designed by the manufacturer during production. For example, if there are 70 basic 8086 commands, the CPU only recognizes the 70 commands, and the CPU is constantly upgrading, in addition to faster running, some new commands will be added. CPU commands are classified into three categories: Transfer, computing, jumpIn fact, our programming language can complete these functions. Transmission is mainly used to manage the memory and manage how data is stored. The calculation is simple, and it mainly involves mathematical computing. The jump enables the computer to be intelligent. What is data?Data can be a number to be calculated, an article, a painting, or a song. These items must be saved in the memory before the CPU can be transferred to the video card or sound card, we can see it. Commands and data are stored separately in the memory. The memory we use when writing a program usually refers to the data zone used to store data. In one command, it is usually divided into operation codes and operands. The operands are also a type of data, but they are only part of the commands and stored in the command area. This type of data is called OperandsAnd will be used later. What is a program,The program is composed of a batch Commands and DataA binary data set composed of a combination. However, if you want to write a program in binary format, it is estimated that some people will be busy. We usually use letters and Arabic numbers that can be understood to write the program. The first programming language to be invented is assembly language, it gives every BINARY command an English name, called the mnemonic code. We use the mnemonic code to write a program, but the CPU doesn't understand it, we have to re-translate it back to binary. We call it compilation. This work was originally completed manually. Later, someone invented the software to enable automatic translation, and the compiler appeared, writing a program in assembly language is a huge step forward than using binary. The efficiency is still very low, so the new language, advanced language, is said to have a language first, with the B Language, the C language finally appeared. Due to its excellent quality, the PK has lost many languages of the same generation and has been widely used until now. Some people are confused. Hard DiskWhy haven't we come out yet? In fact, we have already come out. All the source programs we have written must be stored on the hard disk, and compiled executable programs must also be stored on the hard disk. The memory is Ram, when the power is down, the content will no longer exist. What corresponds to it is Rom, which is permanently saved. There is another classification method for memory: Random storage and linear storage, random storage is the process in which we do not search during access. As long as we say the address and access it right away, linear storage has a search process, telling which cylinder, slice, and track, the data can be accessed only after the motor is rotated. The CPU can only access random memory. Therefore, the memory must be random memory, and the optical disks and hard disks must all belong to linear storage and can only be used for external storage, currently, the popular flash disk is random memory, but it can be used as memory or external storage. A very important program stored on the hard disk is called Operating SystemIn fact, the operating system is composed of a large number of program files and data files. Without an operating system, it is difficult for us to communicate with the computer. The operating system is responsible for managing the entire memory, load the program to be executed by the system into the memory and execute it. This is the process of machine startup. Double-click an executable program with the mouse, and the operating system will remove it from the hard disk, load to the memory. This is the program loading process. The program we mentioned above is loaded to the memory so that it can be executed by the CPU. In addition to managing the memory, the operating system also monitors the execution of each program and ends the program with an exception. If the memory is insufficient, the operating system will first move some of the memory to the hard disk, when it is used, it will be moved back. This part of the hard disk is called virtual memory. It is a waste of time to move data back and forth using the virtual memory. In addition, the reading speed of the hard disk is slow, as a result, the machine becomes very slow, increasing the physical memory, and greatly improving the computer performance by using less virtual memory. In addition, an important feature of the operating system is file management on the hard disk. Different Operating Systems manage the hard disk in different ways. This management method is called File SystemIn principle, a Linux machine cannot be read because it is attached to a hard disk used in a Windows system. However, some software has been developed to access the Windows File System in Linux, therefore, it can be identified and read, but in turn it won't work unless someone develops the corresponding software. Conclusion: 1. core Components of the Computer: CPU and memory 2. the CPU executes commands and stores binary commands and data in the memory. an executable program consists of commands and data. It is written in a high-level language and compiled to generate an executable program. 4. Linear storage and Random storage, Rom and Ram, hard disks, and operating systems


 

Second, the data storage computer is best at storage, and storage is also the soul of the computer, so this tutorial is closely centered around storage, understand and master the storage, you basically understand how to write a program. We just talked about how to store data in the memory. What kind of data can we store? How is it stored? 1. the storage of numbers here refers to the number that represents the size in our calculation. We are used to decimal representation. Computers can only store binary numbers, we can convert it to the corresponding binary number for storage. For example, 254 11111110 is usually written as Fe 5 00000101 05 1) hexadecimal conversion: 1. N: A decimal method: the following equation can be understood by everyone. 3679 = 3*103 + 6*102 + 7*101 + 9*100 this is the calculation method of the decimal number. For the number of N in hexadecimal notation, replace 10 with N, so remember this equation, any hexadecimal to 10 hexadecimal will be done. For example: 10011001 is the binary number converted into a 10 hexadecimal number, that is, 1*27 + 0 + 0 + 1*24 + 1*23 + 0 + 0 + 1*20 = 128 + 16 + 8 + 1 = 153 2. convert decimal to n-base: as before, think about how to find the value of each digit in the 10-base number, 3679/10, more than 9, more than 9, more than 9, more than 367, more than 7, more than 367/10, more than 6, more than 3, more than 3, more than 3, more than 0, and more than 3, divide by 10, the remainder is the lowest number of digits, and then the user is divided by 10. The result is that the remainder is the last digit. The remainder is deleted until the end of the quotient is 0. Error-prone: when dividing 260 by 16, another formula is displayed. The two formula is very similar, and it is easy to confuse accidentally. 3. hexadecimal, Binary Conversion Method: hexadecimal-> binary 1-bit to 4-bit, not 4-bit, front side to zero such: 104-> 0001 0000 0100 Binary-> hexadecimal 4-bit to 1-bit, for example: 101 1100-> 5 C

 

Note: binary is used in the computer, but we always see a lot of hexadecimal numbers. Why? The reason is: binary, hexadecimal conversion is convenient, and it is easy to use, it looks much more convenient to write in hexadecimal format than binary. Therefore, binary is usually replaced by hexadecimal format. Note: any storage is in bytes. Each byte can store two hexadecimal numbers. So we often see two hexadecimal numbers. 2) Multi-byte storage a single byte can only store 8-bit binary numbers and a maximum of 255. What should we do if we want to store a larger number? We can use multiple units to store one number, A large number can be formed after a connection. We usually store the low position on the rightmost right, and store the high position in sequence. The memory is continuous, with only the front and back, with no left or right sides, if a number is composed of multiple bytes, you must specify the order of high and low positions, Low front, high behind. This is critical. Remember. For example, if 258 is written as a hexadecimal value of 01 02, each byte can be saved in two hexadecimal values. Now, two bytes are required. When 02 is stored, 01 is followed by more bytes, and so on. 3) There are positive and negative values in the number of symbols. When a signed number is stored, the highest digit usually represents the sign bit. 1 represents a negative number, and 0 represents a positive number. The number of all symbols in the computer is stored as a complement.Complement definition: the positive value of the complement sign is its own negative number of the complement sign bit remains unchanged, the rest of the BIT is reversed plus 1 if the large storage space saves a small number, the high byte cannot be empty, we can add 0 to a positive value without affecting the size. We must add 1 to a negative value without affecting the size. 2. to store character storage, you need to store a source program, an article, and a string of letters and numbers. These are all stored in character storage. They are different from numbers and do not represent the size, only a table is a letter or number. We usually store it in encoding mode. The most common encoding is ASC code. Each letter and number has a corresponding number, both can be converted to binary for storage, but the ASC code will not work if you want to save Chinese characters. Our country has its own encoding standard gb2312. Haha, Chinese characters can also be saved, however, it takes two bytes to store a Chinese character. Of course, it must be decoded according to the gb2312 standard and then searched for the font for display, some software will automatically select the encoding standard based on the first few bytes of the file or a specified content. In the future, to compile an international program, the encoding must be taken into consideration. 3. A stored image consists of 200x300 vertices. The image has 60000 (200x300) vertices, each of which has its own color, these colors are combined to form an image. If the color of each vertex is saved in one byte, there can be a maximum of 256 colors, which will make the color of the stored image look distorted, if two bytes are used to represent the color, there are 65536 colors that can be expressed, which is basically beyond the resolution capability of the human eye and does not look distorted. If we want to better express the color, the color is stored in 3 bytes, 24 bits, or even 4 bytes, 32 bits. The image is more realistic and the required space is larger. * When a video is played continuously, the animation effect is displayed. If the video is not compressed, the video occupies a large amount of storage space, and the video is compressed and stored. 4. the sound storage is a waveform. We divide the waveform into small segments. The average amplitude of each segment is represented by a binary number and stored. This is called sampling, it is equivalent to storing the sound, which is usually divided into 44 minutes per second. Only 1 K segment can achieve true results. If the sampling frequency is low, the sound quality will decrease. Summary: 1. Data Storage binary, hexadecimal, number conversion, multi-byte storage, and signed data storage. 2. character storage is digitalized and stored after encoding.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.