Representation and processing of information 2.1 information storage
- Machine-level programs treat memory as a very large array of bytes, called Virtual storage .
- Each byte of the memory is represented by a unique number, called its address
- A collection of all possible addresses is called a virtual address space
2.1.16 Binary notation
The hexadecimal transformation method in Python
a=15;print(hex(a))//print:0xf
2.1.2 words
- Length determines the maximum size of the virtual address space
- 32 bits of 4G (2^32)
2.1.3 Data size
char *
The full word length of the machine is used
2.1.4 Addressing and byte order
2.1.5 Represents a String
Any system that uses ASCII code as a character code will represent the same result, regardless of the byte order and word size rules. Thus, text data has greater platform independence than binary data
Java uses Unicode to represent strings. Unicode-enabled libraries are also available for C languages
2.1.6 represents code
Even the same piece of code that uses different, incompatible instructions in different machine types, so the binary code is incompatible.
Introduction to 2.1.7 Boolean algebra
Very simple
- Bit vectors are often used to describe a set (state compression is commonly used)
Bit-level arithmetic of 2.1.8 C language
ACM play a lot of, don't say
Logical operation of 2.1.9 C language
Shift operation of 2.1.10 C language
Logical Right Shift
- Go to the left and fill K 0.
Arithmetic Right Shift
- To the left, fill the value of K's most significant bit
- Have a magical effect on signed operations
Potential problems
- For unsigned data, the right shift must be logical.
- For signed data, logic and arithmetic are all possible.
- Almost all compilers right shift to signed use arithmetic
- Many programmers also assume that using arithmetic to move right
- Potential compatibility issues may exist
2.2 integer representing 2.2.1 integer data type
- have symbols
- No sign
- A negative number is larger than the positive number (there is a 0 that is represented as the smallest negative number)
2.2.2 Encoding for unsigned numbers
2.2.3 Complement code
To understand the complement in this way is a new and good idea.
- It's easy to figure out the range. Turn into the original code without thinking.
- Double shot, rules no special case, it is easy to see that 0 can not express two.
Complement, anti-code
2.2.5 signed and unsigned numbers in C language
- The default is signed, if you need an unsigned tail +u, for example:
12345U
2.2.6 extends the bit representation of a number
- Convert to a larger data type for an unsigned number
- Simply add 0 to the beginning of the representation, which is called the 0 extension
For signed numbers, that is, the complement
- Symbol extension (sign extension), which is the value of adding the most significant bit
Contrast logical right SHIFT, and arithmetic right shift
2.2.7 truncating numbers
Truncate a number to K-bit, that is, to the high w-k.
For unsigned number truncation x it to K-bit results in equivalent
- B2U ([xk-1,xk-2,.... x0]) =b2u ([xw-1,xw-2...x0]) mod 2^k
For a signed number x.
- When truncated, it looks like an unsigned number.
- B2T ([xk-1,xk-2,.... x0]) =u2t (B2U ([xw-1,xw-2...x0]) mod 2^k
)
Suggestions
- Use signed integers in most cases
- Only signed integers are supported in Java,
>>
arithmetic right shifts, >>>
logical right Shift
2.3 Integer Operation 2.3.1 Unsigned addition
2.3.2 Complement addition
Most computers use the same machine instructions to perform signed and unsigned sum.
X (signed +) y= u2t (t2u (x+y) mod 2^w)
-
- Calculate X+y First
-
- Converts x+y to unsigned type Z.
-
- P=z MoD 2^w
- Attached. (or simply truncate the binary representation of the x+y to get P)
-
- To represent P with a signed type
Positive overflow, normal, negative overflow.
2.3.3 complement of non-
2.3.4 unsigned multiplication
- Take only the values represented by the low w bits, and the remaining truncation
2.3.5 Complement multiplication
For unsigned and complement multiplication, the bit-level representation of the multiplication is the same as the same instruction.
The low w bits of the two numbers multiplied by the unsigned and complement are always equal . Proof to see the book.
2.3.6 Multiplication constant
- Because the multiplication speed is too slow, the machine may use (addition, subtraction, shift) instead of multiplication.
2.3.7 divided by a power of 2
For unsigned types or integers, direct right-shift does not have any problems.
For negative numbers, the last value is-48.3, which is rounded to 49 instead of-48.
2.4 Floating point
After that, let's go through something else.
[Csapp notes] [Chapter II Presentation and processing of information]