The representation and processing of the information in the 2nd Chapter
Three important digital representations:
1, unsigned number: The encoding is based on the traditional binary notation, which represents a number greater than or equal to zero.
2. Complement: Encoding is the most common method of representing signed integers, and signed integers are numbers that can be positive or negative.
3. Floating-point number: encoding is a two-bit base version of the scientific notation for real numbers
2.1 Information Storage
Most computers use 8-bit blocks, or bytes, as the smallest addressable unit of storage, rather than accessing individual bits in the storage.
Virtual Storage: The machine-level program treats the memory as a very large byte array.
Address: A unique digital ID for each byte of the storage.
Virtual address space: A collection of all possible addresses
Hexadecimal notation: Beginning with 0x, 10~15 corresponds to A~f
Decimal 16 Binary Conversion: Euclidean method
Word: Length: Indicates the nominal size of the integer and pointer data. Word length determines the most important system parameter is the maximum size of the virtual address space.
Data size: Calculators and compilers support different ways of encoding the number format, and also have instructions for handling single-byte instructions or 2-byte, 4-byte, 8-byte integers.
Addressing and byte order: the most significant bit is the first eight bits and the least significant bit after eight bits. Is the basis of network programming
Small End method: Some machines choose to be in memory by the lowest effective byte to the most significant byte
Big-endian: Some machines choose to be in memory by the highest effective byte to the least significant byte
Note: The small End method "high-to-high, low-to-low" is the opposite.
Represents a string: Text data is more independent than binary data
Boolean algebra: Binary is the core of computer coded storage and operation information
Bit-level operations in C: the C language supports bitwise Boolean operations. With or non, XOR, or common usage is to implement a mask operation.
Logical operations in the C language: logical operators && and | | Bit-level operations that correspond to them & and | The second important difference between the two is if the first
Parameter evaluation can determine the result of an expression, then the logical operator does not evaluate the second parameter.
Shift operations in C: the C language standard does not explicitly define which kind of right-shift should be used. For unsigned data, the right shift must be logical
X<<k: Move K-bit left. X>>k: Shift right 2.2 integer representation
1. Integer data type
Both C and C + + support signed and unsigned numbers by default, and Java supports only signed numbers.
2. Unsigned number encoding
3. Complement code:最高位有效位也称符号位,权重为-2^w-1。符号位为1是负为0是正。
补码的范围不对称,是因为:一半的数的整数一半是负数,而0是非负
数。最大的无符号数值刚好比补码的最大值的两倍大一点。
There are two standard ways to represent signed numbers:
Anti-code: In addition to the most effective bit of the right is-(2w-1-1) rather than -2w-1, it is the same as the complement.
The original code: the most significant bit is the sign bit, used to determine whether the rest of the bit should take negative or positive right.
4. Conversion between signed and unsigned numbers: Defines the function U2TW as U2TW (x) = 4B2TW (U2BW (x)). The input to this function is a number between 0~2w-1, and the result is a value between -2w-1~2w-1-1, where two numbers have the same bit pattern, except that the parameters are unsigned and the result is in complement. Similarly, for the value between -2w-1~2w-1-1 x, the function t2uw is defined as T2UW (x) = 4 B2uw (T2BW (x)), generating a number of unsigned representations and X's complement representation of the same.
Mandatory conversions for different numeric types are supported in the C language. The general rule for converting between signed and unsigned numbers with the same word length is that the value may change, but the bit pattern is not changed when a signed number is mapped to its corresponding unsigned number, negative numbers are converted to large positive numbers, and non-negative numbers remain unchanged. Signed and unsigned numbers in 5.C languages: signed by default, most numbers are signed by default to create an unsigned constant, add the suffix u/u.the principle of C language translation is that the underlying bits remain unchanged. None to have: U2TW. Have to none: T2uw
6 Extend the bit representation of a number to convert between integers of different lengths, while keeping the values constant.
0 Extension: Add 0 at the beginning
7. Truncate number: Reduces the number of digits that represent a number.
2.3 Integer Arithmetic
1. unsigned addition: unsigned addition is equivalent to computation and modulo 2w. This value can be calculated by simply discarding the highest bit represented by the W + 1 bits of x + Y. Can be considered as a form of modulo operation, which is equivalent to calculation and modulus 2^w.
Overflow: Full integer result cannot be placed into the word length limit of the data type
2. Complement addition: negative overflow results are larger than integers and large 16, and positive overflow results are 16 smaller than integers.
3. Complement of non-
4. The formula is calculated without symbolic multiplication.
5. Complement multiplication: Two bit vectors for a given length, the bit-level representation of the unsigned product is the same as that of the complement product, indicating that the machine can use a multiplication instruction to multiply the signed and unsigned numbers.
6. Multiply constants: In order to shorten the computational time, many C-language compilers try to replace multiplication by multiplying constants with a combination of shift, addition, and subtraction operations.
7. The power of dividing by 2: the Power of dividing by 2 can be achieved by logical or arithmetic right shift.
8. The final thought on integer arithmetic: The computer performs the "integer" operation is actually a form of modulo operation. A finite word length that represents a number limits the possible range of values, and the result can overflow. The complement provides a flexible way for skills to represent positive numbers and to represent negative numbers, while using the same bit-level implementation as the execution of unsigned arithmetic.
2.4 Floating point
1. Binary decimals: The inverse of the divide method, the negative power of 2.
2. IEEE Floating point representation:
Standard: v= ( -1) ^sM2^e.
Symbol: s determines the positive or negative number.
Mantissa: M is a binary decimal.
Order code: The role of E is weighted against floating-point numbers,权重是2 的E次幂。
Case 1: Normalized value. When exp is not full modulus is 1 or 0. The Order field is interpreted as a biased representation of a signed integer.
Case 2: Non-normalized value: When the Order field is full 0 o'clock, the number represented is a non-normalized form. In this case, the order value is E = 1-bias, and the value of the mantissa is M = f, which is the value of the small number field, which does not contain the implied beginning of 1
Case 3: Special Value: The Order field is all 1. The decimal field is all 0, and the resulting value represents infinity. Also useful when representing uninitialized data.
3. Numeric examples
4. Rounding: A floating-point operation can only approximate the representation of the number of operations to find the nearest X value is rounding, the key to the problem is to determine the rounding direction between the two possible values.
The default method finds a close match, and the other three are used to calculate upper and lower bounds (rounded to 0, rounded down, rounded up).
Rounds an even number (default): A positive number is rounded up and a negative number is rounded down.
5. Floating-point arithmetic: The IEEE standard specifies a simple rule that determines the results of arithmetic operations such as addition and multiplication. Floating-point addition does not have a binding but satisfies the monotonicity attribute but only has a limited range and precision.
Floating-point number in 6.C language: float double
20135327 Guo Hao--Information security system design basics Third Week study summary