CSAPP - Ch 2 - and represented by the information processing

0 basic concepts and summary

(1) Basic concept:

Modern computer information storage and processing of signals in binary - 0 | 1, non-presence or absence of black and white, represents the computer is accurate.

The computer representation is a limited number of bits (bit) to a digital encoding, if the number is too difficult to represent, some operators will overflow (overflow) **.

There are three digital representation:

a) no sign (unsigned) encoding: represents a number greater than or equal to 0;

b) complement (two's-complement) encoding: represents signed integers (may be positive or negative number) is the most common way;

c) floating-point number (floating-point) encoding: scientific notation represented by real numbers, the base 2 version.

Integer and floating-point operations have different mathematical properties - they deal with the limited numbers indicate different ways:

Although only represents an integer of encoding a relatively small range of values, but this representation is exact;
float may encode While a large range of values, but this represents only approximate.

1 Information Store

Most computer 8-bit (bit) blocks or bytes (byte) , as the smallest addressable unit of memory, rather than a single-bit memory accesses.

Each byte of memory by a unique number to identify - this number is called address (address) , the set of all possible addresses referred to the virtual address space (address Virtual Space) - a logical concept, conceptual image.

1.1 hexadecimal notation

A byte consists of 8 bits, in binary notation, its scope (range) is 00000000 to 11111111 , the corresponding decimal 0 to 255 .

To avoid lengthy binary representation method, taking into account the easy conversion between the bit, we hex (hexaecimal) to represent a bit pattern, a byte range is 0x00 ~ 0xFF .

(1) hexadecimal notation:

Hex 0 1 2 3 4 5 6 7
Decimal 0 1 2 3 4 5 6 7
Binary 0000 0001 0010 0011 0100 0101 0110 0111
Hex 8 9 A B C D E F
Binary 1000 1001 1010 1011 1100 1101 1110 1111
Decimal 8 9 10 11 12 13 14 15

Note: In the C language, to begin with 0x or 0X numeric constants are considered hexadecimal value
character 'A' ~ 'F' may be uppercase, lowercase may be.

(2) between the base for the conversion:

0x7AF converted to decimal as:

7 * 10 * 16 ^ 2 + 1 = 16 + 15 * 1967
wherein the second position 7, A at position 1, F in bit 0, respectively, so that power by 16 ^ I.

And 1967 to hexadecimal:

1967/16 = 122 --- extra 15
122/16 = 7 --- over 10
7/16 = 0 --- extra 7

The final remainder reverse order, obtained is the result: 0x7AF.

1.2 Data word size

Each computer is represented by a word (Word size) , nominal size specified pointer data (nominal size) - is such a virtual address to encode a word, so the word length determines the maximum virtual address space of the system size:

32-bit word length limits the virtual address space is 4 gigabytes (writing 4GB), just over 4 10 ^ 9;
64-bit virtual address space is arbitrary limit 16EB, about 1.84
10 ^ 19.

The basic data types typical size C:
The basic data types typical size C

The exact number of bytes Some data types depend on how the program is being compiled.

Program has "32-bit program" or "application 64" points, the difference lies in how the program is compiled, rather than the host operating machine type.

ISO C99 introduces a class of data types, whose size is fixed and does not vary with the compiler and the machine settings, which have the data type int32_t(4 bytes) and int64_t(8 bytes).

Determined using integer type size is the best way data is represented accurately control developers. Developers should try to make portable applications on different machines and compilers, one aspect of portability is to make the program the exact size of different data types insensitive .

And byte order addressing 1.3

Program objects across multiple bytes, two rules must be clear:

What address 1) the object is?
2) how to arrange these bytes in memory?

Some machines selected in memory from the least significant byte to most significant byte is sequentially stored objects, referred to Little-Endian (Little endian) ;

Some machines are just the opposite: the most significant byte -> the least significant byte, called the Big-Endian (Big endian) .

In an example of type int variable x, which is a hexadecimal value of 0x01234567, the address range 0x100 ~ 0x103 byte order dependent on the type of machine:

Large and small ends of different storage methods

Extensions:
Most Intel compatible only with the little-endian mode, while IBM and Oracle with most machines are big-endian mode.

But some PC IBM and Oracle manufactured using Intel-compatible processors, so using little-endian.

Although some newer microprocessors double-ended method (bi-endian), the actual situation is: Once the operating system is selected, then the fixed byte order along with it, big endian and little-endian can not presence.

To be continued ...

Guess you like

Origin www.cnblogs.com/shoufeng/p/11489044.html