Linux Experiment 3

Source: Internet
Author: User
Tags arithmetic

I. Learning Objectives

1. Understanding the importance of binary systems in Computers 2. Mastering the application of Boolean operations in C language 3. Understanding signed integers, unsigned integers, and floating-point number representations 4. Understanding the importance of complement 5. Avoids overflow in C language, traps in data type conversions, and vulnerabilities that can be caused

Second, learning Resources

(Hint: optional, if you have other related resources, please specify here):

1. Teaching Materials: Chapter II, "Information representation and processing", detailed study guide see this.

2. Course Material: https://www.shiyanlou.com/courses/413 Experiment Three, course invitation code:w7fqkw4y

3. The code in the textbook run, think about, read the code of learning methods see this.

Iii. Methods of Learning

(Hint: In order to improve students ' learning effect, please provide students with specific requirements or suggestions for micro-curriculum study here.)

1. Progress is important: you must keep up with weekly progress, readings, exercises, quizzes, and projects. I will take every student seriously, please don't give up because of difficulty.

2. Question and answer is very important: meet the knowledge difficulties, please ask a lot of questions, this is your right to be responsible for your own obligations. Question and answer to the blog Park discussion group: http://group.cnblogs.com/103791/3. Practice is important: solve the book exercises, practical examples, complete the weekly project, only to really digest this good book. Study in practice through lab building environment or virtual machine installed by yourself 4. The experiment report is important: keep track of your ideas for completing project tasks, get teacher reviews and help yourself review. After the completion of the study in the blog Park (http://www.cnblogs.com/) The study process through the blog published, blog title "Information Security system design fundamentals of the third Week study summary"

Iv. Learning Tasks

(Tip: List tasks, quizzes, or study questions that require students to complete here)

1. Read the textbook and complete the After-school practice (the book has a reference answer)

2. Examination: Exercises to change the data

3. Bonus points: After-school homework up to two groups, can not repeat each other, 1-star topic per person up to a point, 2 star topic per person up to two points, 3 star topic per person up to three points, 4 star topic each person the most four points.

Five , follow-up study notice (optional):

Teaching Materials Chapter III "Machine-level representation of procedures"

six . Learning process

Chapter II Identification and processing of information

Computer storage and processing information is represented by a two value signal.

Three of the most important digital representations

Unsigned: Based on traditional binary notation, greater than or equal to 0

Complement: Signed integer

Floating-point numbers: A binary-based version of the scientific notation for real numbers

Buffer Overflow Vulnerability:

The representation of a computer is to use a finite number of bits to correspond to a number encoding, and overflow occurs when the result is too large to be represented. An artificial overflow is an attempt by an attacker to write a string that is longer than the buffer length, which may result in two types of results: one is that the long string overwrites the adjacent storage unit, causing the program to fail, causing the system to crash seriously, and the other result is to exploit the vulnerability to execute arbitrary instructions. You can even get the system root privilege.

2.1 Storage of information

1. Each byte of the memory is identified by a unique byte and becomes its address. The collection of all possible addresses becomes the virtual address space. It combines time-based random access memory (RAM), disk storage, special hardware, and operating system software.

2. Hexadecimal notation

Beginning with 0x or 0X, the character a-f can be uppercase and lowercase.

! Mastering the conversion between binary and hexadecimal, the binary four-bit corresponds to a hexadecimal one.

Tips:

3. Word

Word length: Indicates the nominal size of the integer and pointer data. The most important system parameter determined by the word length is the maximum size of the virtual address space. For a machine with a W-bit length, the virtual address range is 0-2^ (w-1), and the program accesses up to 2^w bytes.

4. Data size

5. Addressing and byte order

Small-End method: Storing objects in memory in the order of the most effective bytes from the lowest valid words;

The big-endian method: Store objects in memory in the order of the most effective words to the lowest valid bytes;

Example: the variable x hexadecimal value is 0x01234567, then:

6. Represents a string, code

A-Z asc| | The code is 0x61-0x7a.

7. Boolean algebra

Use 0, 1 to express true and false, to study the basic principles of logical reasoning.

There are: ~=not;&=and;|=or;^= or different.

8. Bit-level arithmetic in C language

!! The best way to determine the result of a bit-level expression is to extend the hexadecimal parameter to binary identification and perform the binary operation, and then convert back to 16 binary.

9. Logical operations in C language

Have: | |, &&,! , corresponding to or, and and not operations, respectively.

! Note: The logical operation considers all nonzero parameters to represent true, and parameter 0 indicates false.

10. Shift operations in C language

Right-shift operation:x>>k; left-shift operation: X<<k.

! For unsigned data, the right shift must be a logical right shift. For signed data, you can also make arithmetic move right.

2.2 Integer Representation

1. Unsigned number encoding

2. Complement code

3. Extends the bit representation of a number

0 extension-Converts an unsigned number to a larger data type, adding 0 at the beginning.

Symbol extension--converts a complement number to a larger data type, adding a copy of the high-efficient position to the representation.

4. Truncate numbers

2.3 Integer Arithmetic

Includes unsigned addition, complement addition, complement non-, unsigned multiplication, complement multiplication, multiplied by constant, and power divided by 2.

1. Unsigned addition is a form of modulo operation.

2. Complement addition, the sum of the two-digit W-complement is the same as the unsigned sum of the same bit-level representation. Define the length of W, the number of operands x, and the complement addition on y as:

Therefore, it can be concluded that:

3. Complement of non-

4. Unsigned multiplication

5. Complement multiplication

6. Multiply constants

!! Note: Multiplying by a power of 2 can result in overflow, whether it is an unsigned operation or a complement operation. But even if it overflows, the results are the same.

7. The power of dividing by 2

The power of dividing by 2 is achieved by a logical or arithmetic right shift. But this method cannot be generalized to divide by any constant.

2.4 Floating point

1. Binary decimals

Decimal binary representation, the left of the binary point of the right shape as 2^i, and the right of the number of the right shape, such as 1/2^i.

2. IEEE Floating point representation

3. Floating point Arithmetic

The IEEE standard defines some reasonable rules. Defining 1/-0 will produce-∞, and defining 1/+0 will produce +∞.

An advantage of specifying a floating-point arithmetic behavior method in the IEEE standard is that it can be implemented independently of any specific hardware or software.

Floating-point addition is not binding, which is the most important group attribute missing, and floating-point addition satisfies the monotonicity attribute-if a>=b, then for any a\b and x values, there are x+a>=x+b except Nan. unsigned or complement addition does not have the attribute of this real (and integer) addition.

Floating-point multiplication satisfies the following monotonicity:

4. Floating-point numbers in the C language

All C language versions provide two different floating-point data types: float and double. On machines that support IEEE floating-point format, these data types correspond to single-precision and double-precision floating-point.

The newer version of the C language, including the ISO C99, contains the third floating-point data type long double. For many machines and compilers, this data type is equivalent to a double data type. However, for Intel compatible machines, GCC uses the 80-bit "extended precision" format to implement this data type, providing a much larger range and precision than the standard 64-bit format.

Three different floating-point data types: float, double, long double (equivalent to double for many machines and compilers).

! When casting between the int, float, and double formats, the principle of changing the sum bit pattern of the number of programs is as follows (assuming that int is 32-bit):

Vii. problems encountered and their solutions

Viii. Other

(Hint: this is filled by students, inspiration, comprehension, etc.)

Linux Experiment 3

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.