Representation and processing of information (In-depth understanding of computer systems Chapter 2)

Not long after learning this book, I feel that there are quite a lot of things in it, and the correlation between the front and the back is relatively strong. After learning the latter, you need to look at the former to understand better.

2.1 Information storage

Unsigned (unsigned) encoding is based on traditional binary notation, representing numbers greater than or equal to zero.

Two's-complement encoding is the most common way to represent signed integers,
which are numbers that are either positive or negative.

A floating-point encoding is a base-two version of scientific notation for representing real numbers. Computers use these different representations to implement arithmetic operations, such as addition and multiplication, similar to the corresponding integer and real number operations.
Computer representations encode a number with a finite number of bits, so certain operations overflow when the result is too large to represent. This has some surprising consequences. For example, evaluating the expression 200*300*400*500 yields -884901888 on most computers today. This violates a property of integer arithmetic—calculations—the product of sets of positive numbers yields a negative result.
 

Most computers use 8-bit blocks, or bytes, as the smallest addressable unit of memory, rather than
accessing individual bits in memory. Machine-level programs see memory as a very large array of bytes called virtual memory. Each byte of memory is identified by a unique number called its address, and the collection of all possible addresses is called the virtual address space. As its name suggests, this virtual address space is just a conceptual image presented to machine-level programs. The actual implementation (see Chapter 10) uses a combination of random access memory RAM, disk storage, special hardware, and operating system software to provide the program with a seemingly uniform array of bytes. 

big endian little endian

Add a 12345 binary conversion and hexadecimal conversion

12345的二进制表示是:
11000000111001
转换步骤:
1. 12345 ÷ 2 = 6172...1  
2. 6172 ÷ 2 = 3086...0
3. 3086 ÷ 2 = 1543...0
4. 1543 ÷ 2 = 771....1
5. 771 ÷ 2 = 385....1  
6. 385 ÷ 2 = 192....1
7. 192 ÷ 2 = 96.....0
8. 96 ÷ 2 = 48.....0
9. 48 ÷ 2 = 24.....0
10. 24 ÷ 2 = 12.....0
11. 12 ÷ 2 = 6.......0
12. 6 ÷ 2 = 3.......0 
13. 3 ÷ 2 = 1.......1
14. 1 ÷ 2 = 0.......1
所以12345的二进制表示是11000000111001。

12345的十六进制表示是:
3039
转换步骤:
1. 12345 分解成12345 = (1 * 16^3) + (2 * 16^2) + (3 * 16^1) + (9 * 16^0)
2. 1 * 16^3 = 4096   (1 -> 十六进制数字1)
3. 2 * 16^2 = 512    (2 -> 十六进制数字2)
4. 3 * 16^1 = 48     (3 -> 十六进制数字3)
5. 9 * 16^0 = 9      (9 -> 十六进制数字9)
3. 将每个部分的十六进制数字组合:
   4096 -> 1000
   512 -> 0200
    48 -> 0030
     9 -> 0009
4. 合并每个部分的十六进制数字:
   1000 0200 0030 0009
5. 去掉前导0,得到十六进制数:
   3039
所以,12345的十六进制表示是3039。

Like Sum, the least significant bit of 12345 is 39, and the first output is a small-segment machine such as Linux NT, but like sum, the last output 30 is a big-endian machine.

Logical operations and bit operations

    bit operation

Like blue and green, the result is 011, which turns into blue-green

logic operation

 The logical operation is only true if it is a non-zero number, and it is false if it is 0;

Summary: Bit operations have specific values ​​while logic operations only have the difference between 0 and 1. The same situation is that only two are binary and one.

integer representation

 The biggest differences between 32-bit and 64-bit computers are as follows:
1. Address space size
The maximum addressing space of a 32-bit computer is 4GB, and the addressing space of a 64-bit computer can reach 16EB. This means that 64-bit computers can support larger physical memory.
2. Length of registers and assembly instructions
The length of registers and assembly instructions of a 32-bit computer is 32 bits, and that of a 64-bit computer is 64 bits. This allows 64-bit computers to process more data in a single operation.
3. The data type of the operand
The native data type of the 32-bit computer is 32 bits, such as int, etc. 64-bit computers have added 64-bit long and pointer types, which can perform 64-bit operations more efficiently.
4. Compatibility
Most 64-bit CPUs can run 32-bit code compatible. But a 32-bit CPU cannot run 64-bit code.
5. Memory addressing
32-bit computers can address up to 4GB of memory space, and 64-bit computers can address more than 16EB of memory space.
6. Security
64-bit computers provide higher security, such as increasing the length of registers to prevent buffer overflows.
7. Performance
64-bit computers have stronger computing performance and can better support data-intensive and computing-intensive applications.
In summary, 64-bit computers are superior to 32-bit computers in terms of address space and performance. This allows 64-bit computers to support larger and more complex applications.

The binary representation of 12345 is 0011 0000 0011 1001

The complement is 1100 1111 1100 0111

The complement of 12345 is the binary form of -12345

When 1100 1111 1100 0111 is used as an unsigned number, the value is: -12345+32768+32768=53191 

When the second mechanism of 53191 plus the value of 12345 minus one is 1111 1111 1111 1111 is INT_MAX which is 65535

If it is not reduced by one, it is 0; it becomes 0000 0000 0000 0000; it means that the source code of a number plus the complement is 0;

                                                                

Guess you like

Origin blog.csdn.net/qq_64200765/article/details/131910731