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 representationsUnsigned: 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):
|