Chapter II 2.1 Information storage 1, the number of three kinds of representations
Unsigned number: A traditional binary notation that represents a number complement that is greater than or equal to zero: represents a signed number, which can be a negative numeric floating-point number: The binary-based version of the scientific notation for real numbers and the calculation of floating-point numbers have different mathematical properties. Cause: The way numbers are represented is limited in different integer representations: The encoded range of values is relatively small, but the exact number of floating-point numbers indicates that the numeric range of the encoding is relatively large, but the approximate computer operations are caused by the microsecond details of the computer's arithmetic operations.
2. Conversion conversion (1) x=2^n to Hex
Writes X in the form of x=2^n, so that the hexadecimal representation of n=i+4j,x is: A value beginning with 2^i, followed by J 0.
(2) decimal conversion to hexadecimal
Decimal number x repeatedly divided by 16 hexadecimal number
(3) hexadecimal conversion to decimal
Hexadecimal number x repeatedly multiplied by 16, decimal number
3, Word and byte order
Word length: A word length indicates the nominal size of integers and pointer data. Word length determines the most important system parameter is the maximum size of the virtual address space. For a machine with a word length of w, the scope of the virtual address is 0~2^w-1, and the program accesses up to 2^w bytes. There are two rules for a program object that spans multiple bytes: What is the address of this object and how these bytes are arranged in memory. Small-ended method: high-to-high, low-to-low-end method: Visually, is the order of this reading, in contrast to the small-end method. Three ways to make the byte order visible: When the binary data is transmitted over the network between different types of machines, the code of the network application must follow the established rules for byte order, and use the disassembler to deal with the byte sequence of bytes for integer data; When writing programs that circumvent the normal type system.
4. Operation of Boolean algebra (1) Bit vectors: application of bitwise arithmetic (2) bit vectors: representing a finite set
A mask represents a collection that is set to a valid signal.
(3) Bit-level arithmetic
|: or &: and ~: Negation ^: The best way to vary or determine the result of a bit-level expression is to extend the hexadecimal parameter to binary representation and perform a binary operation, and then convert to 16 binary. Common algorithms for W-bit-level operations: Mask Operations . Mask Operation : The mask is a bit pattern that represents a collection of bits selected from a word. For example, bit-level operations X&0xff generate a value that consists of the lowest valid byte of x. The expression ~0 will generate a full 1 mask, regardless of the machine's word size.
(4) Logical operation
Logical operators: | | (or), && (and),! The (non) logical operation considers all nonzero parameters to represent true, and parameter 0 represents false. Returns 1 or 0, respectively, indicating that the result is true or false. The difference between a logical operation and a bit-level operation is that bitwise operations can have the same behavior as the corresponding logical operation only in special cases where the parameter is limited to 0 or 1 o'clock; If the first parameter evaluates to determine the result of the expression, the logical operator does not evaluate the second argument.
(5) Shift operation
Left K bit: discard the highest bit of K-bit, right-side complement K 0 right shift includes: logical right shift, arithmetic right shift logic right Shift: Left complement K 0(commonly used in unsigned number) arithmetic right shift: Left to complement K most significant bit value (for signed number)
2.2 Integer Representation1. Complement code
The complement form is the most common symbolic number of computer representations that interpret the most significant bits of a word as a negative weight b2t (W) function: b2t (x) =-X (w-1)2^ (w-1) +∑xi2^i (sum from i=0 to i= W-2)
2. Conversion between signed and unsigned numbers
The general rule for handling the conversion between signed and unsigned numbers of the same length: The value may change, but the bit pattern will not change. The C language allows conversions between unsigned and signed numbers. The principle of conversion is that the underlying bit representation remains unchanged. When converting from an unsigned number to a signed number, the effect is to apply the function u2t, from the signed number to the unsigned number, to apply the function t2u, where w represents the number of bits of the data type. cases where negative and positive numbers are equal: u=2147483648 =-2147483648 (when the output is unsigned and signed respectively)
3, the bit representation of the extension number
0 Extension: Convert unsigned number to a larger number add 0 symbol extensions at the beginning of the representation: convert a complement number to a larger data type
4. Truncation of Numbers
Truncate a number: Instead of an extra bit to extend a number, the number of digits representing a number is reduced.
5, the use of unsigned number case
(1) The word is only regarded as a set of bits, and does not have any numerical meaning (2) when the mathematical package for modulo and multi-precision operations is implemented, the numbers are represented by arrays of numbers, and unsigned values are also useful.
2.3 integer arithmetic 1. unsigned addition
Unsigned operations can be considered as a form of modulo operation, and unsigned addition is equivalent to calculating and touching the 2^w, which can be calculated by simply discarding the highest bit represented by the w+1 bit of the x+y. An overflow of an arithmetic operation means that the complete integer result cannot be placed into the word length limit of the data type.
2. Complement addition
the sum of the two-digit W-complement is represented by the exact same bit-level as the unsigned sum. Most computers use the same machine instructions to perform unsigned or signed additions. The result of signed addition Z=x+y can be divided into 4 cases: (1) -2^ (w) ≤z<-2^ (w-1): Two negative numbers add a nonnegative result. (2) -2^ (w-1) ≤z<0: The result is normal, Z is negative (3) 0≤z<2^ (w-1): The result is normal, Z is positive (4) 2^ (w-1) ≤z<2^ (W): Two positive numbers add a negative result.
3. Complement of non-
For x in the range -2^ (w-1) ≤x<-2^ (w-1), the complement does not operate as follows: (1) x=-2^ (w-1): Complement of non- -2^ (w-1), (2) x>-2^ (w-1): Complement of non-X. The method of finding the complementary complement is: (1) to complement each one, then add 1 to the result, and (2) build on the basis of dividing the bit vectors into two parts.
4. Unsigned multiplication
Two digits x, y multiplied by x, Y, and the number of bits is w, then the result is 2w.
5. Complement multiplication
With no symbolic multiplication. If the result is truncated, the subsequent w bit of the result is taken as the result of the calculation. Note: Unsigned and complement operations have the same result on the "+", "-", "*" at the bit level.
6. Multiply constants
For an expression of a constant k X*k generates code, the compiler will express the binary representation of K as a set of alternating sequences of 0 or 1: [(0 ... 0) (1 ... 1) (0 ... 0) ... (1 ... 1)] The results of these products can be calculated in the following two ways: A: (x<<n) + (x<<n-1) +......+ (x<<m) B: (x<<n+1)-(x<<m)
7. The power of dividing by 2
Set x/k, make K=2^n, when X is positive, calculate x>>n; When x is negative, the X is added to the offset, that is, with 2^n-1 (that is, K-1), to calculate the * * (x+ offset) >>n**.
8. The final thought on integer arithmetic
The "integer" operation performed by the computer is actually a form of modulo operation, which indicates that the finite word length limit of a number is the range of possible values, and the result of the operation may overflow; The complement representation provides a flexible method that can represent negative numbers and positive numbers, while using the same bit-level implementation as the execution of unsigned arithmetic; The use of unsigned data types in the C language should also be particularly noted, for example, when writing integer constants and invoking library functions.
2.4 Floating point (1) binary decimals
convert decimal decimals to binary decimals first, the decimal fraction is written in the form of fractions, the numerator part of the fraction is written in binary form, and the denominator part of the fraction is written in the form of 2^n, and the binary form of the numerator is added, from right to left and number N. Shift the decimal point to the left: divide by 2 to the right: multiply by 2
(2) IEEE floating-point number representation
The representation is: V = ( -1) ^s * M * 2^e symbol: s Determines whether the number is negative (s = 1) or positive (s = 0), while the symbolic bit interpretation for the value 0 is handled as a special case. Mantissa: M is a binary decimal that has a range of 1 to 2-ε, or 0 to 1-ε. Order code: The role of E is weighted to the floating point data, which is 2 of the power of the E (possibly negative). According to the value of the order code, can be divided into three cases: condition One: Normalized value (when the Order field is not all 0 or
(3) Rounding of floating-point numbers
There are four scenarios: rounding to even numbers (default), rounding to 0, rounding down, rounding up.
(4) floating point arithmetic
Floating-point addition: does not satisfy the binding, satisfies the monotonic floating-point multiplication: does not satisfy the binding, satisfies the monotonicity, does not satisfy the distributive in the addition
All is 1 o'clock) E = E-bias Bias = 2^ (k-1)-1 M = 1+f
Information Security system Design Fundamentals third Week study summary