Dark Horse Programmer---C basic 6 "#include指令" "Modular Programming" "Computer-based" "native code, inverse code, complement" "Bitwise operator"

Source: Internet
Author: User
Tags bitwise operators

------Java Training, Android training, iOS training,. NET training, look forward to communicating with you! -------

"#include指令"

1. The file contains the format of the command:

1) #include "" Double quotation marks are files that contain the user's own written definition (which can be a header file or an ordinary file) #include是预处理指令, not a statement, no seal number required

2) #include <> header file containing a system (compiler comes with)

2, the document contains the essence:

Inserts the specified file contents into the command line position instead of the command line,

Include is not necessarily written on the first line;

3. Include File search order:

Replace the contents of the A.txt file in the current directory with the current write include;

Current directory: and Main. c a directory under the same folder;

#include "" The user's own

1) Look under the path where the current file is located;

2) If not found above, to the compiler include path lookup;

3) If the compiler include path is not found, the system's include path to find;

4) If the above three are not found on the error;

#include <> header file containing a system (compiler comes with)

1) Search under the include path of the compiler;

2) If you do not go to the system include path to find;

3) If there is no error;

"Modular Programming"

1. Modular Programming Concept:

The so-called modular programming (multi-file development), is the multi-file (. c file) programming, one. C File one. H file can be called a module;

The functions similar functions are encapsulated in different files;

2. Header files are used in the following scenarios:

1) through the header file to call the library function;

In many cases, the source code inconvenience to the user to publish;

2) Multi-file compilation

A slightly larger project is divided into several file implementations;

3) header file to enhance type of security check

3. Realize:

. C C Language source files:

. h (header) header file

1) method declaration but unable to implement method

2) Declaring a variable cannot define a variable

3) Declare the structure body;

4. Benefits:

1) time is only included. h file, external hidden source file

2) Division of the team

3) The function can be subdivided into several modules

5, multi-file development implementation (Modular development Implementation):

Liezi:

Implementation calculator:

1) Calculation link

2) Display Results

"The computer's binary"

1, the concept of binary:

is a way of counting, the representation of a numerical value;

2, common in the system:

Decimal, binary, octal, hexadecimal;

3, the binary digital Carry method:

Decimal: 0.1.2.3.4.5.6.7.8.9 every ten into one;

Binary: 0.1 every two in one,

Writing form: Need to start with 0b,0b, 0b101

Octal: 0.1.2.3.4.5.6.7 every eight in one, starting with 0, 045

Hex: Every 16 into one, 9,a,b,c,d,e,f, to 0x,0x beginning, 0x45;

4. Elements of the binary conversion:

1) Digits

A digit is the position of a digital in a number;

76543210

01100100

5. Conversion

10 binary Conversion 2 binary,

In addition to the second, decimal by 2 rounding method, high 0, the remainder of the reverse is the binary

2 Binary Conversion 10 binary

The right to add a bit,

2 binary Conversion 16 binary:

Integer part from right to left four bits and one, fractional part from left to right four bits and one; 4 in 1;

16 Binary Conversion 2 binary:

Convert 16 binary constants to 2, each split into 4 for bits, not enough for 0

"Original code, anti-code, complement"

1. Concept:

The method of storing data in a computer is in the form of complement and storage;

The data is divided into signed number, and unsigned number;

The maximum number of positive digits is 0, the highest negative number is 1;

For positive numbers: anti-code = = Complement = = Original Code

For negative numbers: anti-code = = Except for the sign bit, you take the reverse. complement = anti-code +1

2, the original code:

The original code is the absolute value of the symbolic bit plus the truth "+1" source =0000 0001 "1" Source =1000 0001

The range of values for 8-bit binary numbers is:

1111 1111, 0111 1111; positive 127 to negative 128

3, anti-code:

Positive inverse code is itself, negative anti-code is the sign bit unchanged, the rest of you take the reverse

4. Complement :

Positive complement is itself, negative numbers are added 1 on the basis of anti-code;

[+1] source =0000 0001 = 0000 0001 complement

[-1] source =1000 0001 = 1111 1110 anti = 1111 1111 complement;

5, why to introduce anti-code

Computer recognition symbol bit, subtraction is added a negative number, the computer can not do subtraction, the original code to calculate the negative 0;

"Bitwise operator"

1, bitwise operators

A binary calculation; applied only to an integral type.

1) & Bitwise AND: 9&4=0, with 1 The result is 1, 0 result is 0; any cardinality and 1 are 1; even and 1 are 0;

2) | The bitwise OR 1 is 1, the same 0 is 0;

3) ~ 1 0,0 change to 1;

4) ^ Bitwise XOR or Same as 0, different 1

5) >> Right shift each binary all right shift n bit, low drop, high 0, equivalent to the original number/2^n;

6) << left displacement of each binary all left n bits, high drop, low 0, moving to the left N-bit, equivalent to the original number *2^n; may change the positive and negative of a number;

2, Practical:

Any cardinality and 1 and both are 1; even and 1 are 0;

can use left and right to move again &1 the method to carry on 10 to convert 2 to enter the system;

1 int a=3, b=4; 3 //     a=a-b; 5 //     b=b+a; 7 //     a=b-a; 9     a=a^B;  One     b=a^B;  -     A=a^b;   

Two number Exchange

Dark Horse Programmer---C basic 6 "#include指令" "Modular Programming" "Computer-based" "native code, inverse code, complement" "Bitwise operator"

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.