"In-depth understanding of computer systems" 2.1 Information storage

Source: Internet
Author: User
Tags binary to decimal

Information Store

The machine-level program treats the memory as a very large byte array calledVirtual Memory, each byte of the memory is identified by a unique number, called itsAddress, a collection of all possible addresses is calledVirtual address spaceThis virtual address space is just a conceptual image of a machine-level program. The actual implementation is to combine random access memory (RAM), disk storage, special hardware, and operating system software to provide a seemingly uniform byte array for the program. Binary Conversion10 ext .This method only powers the integer number of decimal 2, such as decimal 512, as 2^9. Write 9 to 1*.I+4*J, namely 1*1+4*2。 That is, its 16 binary starts with a 2 followed by 2 zeros.

Other methods related to the conversion are not described in detail using only examples to illustrate the following diagram sources a training institutionarbitrary binary to decimaldecimal turn arbitrary binary8421 yardsAnti-code, complement, original code

WordEach computer has a word length that indicates the nominal size of the integer and pointer data. Most computers have a length of 32 bits, so it has a 2∧32 address of about 4GB in size, that is, its virtual address space is the largest so much. Data SizeMany machines can handle single-byte, 2,4,8 bytes (64-bit). For a 32-bit machine, he will process 64 bits into a series of 32-bit operations code. Programmers should strive to make their programs portable on different machines and compilers,For example, declaring an int (32-bit size) type of program object can be used to store a pointer, but running the program on a 64-bit machine can be problematic   Addressing and byte orderFor a program object that spans multiple bytes, we must establish two rules:
    1. What is the address of this object?
    2. How these bytes are arranged in the storage
What's the address?Almost all machines,The address of the object is the address of the smallest byte used, for example: an int type data has a four-byte address of 0x001,0x002,0x003,0x004, the address of this int data is 0x001.How to ArrangeBig-endian and small-end storage (note that data is stored!) Non-address)Small-End storage: The machine stores objects in memory in the order of the lowest valid bytes to the most efficient byte, that is, the lowest valid byte is in front, and so is Intel's machine.Big- endian storage: The machine stores objects in the order of the most significant bytes to the lowest valid byte for example: there is an int type of data with the address of 0x100, and its saved 16 binary data is 0x01234567 (16 binary per two digits are stored in 1 bytes, 01 is high Byte, 67 is low byte)
Usually the byte order used by the machine is not visible but sometimes the byte order may become problem 1, when the binary data is transmitted over the network between different types of machines, the small-end method machine produces the data to the big-endian machine into reverse order. To avoid this problem,code writing must obey the rules of byte order2, byte order is also important when reading byte sequences of integer data 3, when writing programs that circumvent the normal type system. (Forced type conversion) Boolean algebra bit vectors : A string with a fixed length of W, consisting of 0 and 1&~ Take anti-|^& to | have distributive law:a& (b|c) = (a&b) | (a&c) | There are also distributive laws for &: a| (b&c) = (a|b) & (A|c)bit vectors can be used to represent a finite set。we can useBit vector[Aw1,....., a1,a0] encode any What subset a∈{0,1,....,w-1} where Ai=1 is and only if i∈a. For example, (remember that we are aw-i written on the left,The A0 is written on the right, which is written in the opposite direction), the bit vector a=[01101001] (the last one is 1, the description set has 0, the penultimate 4th is 1, the name set has 3)represents the collection a={0,3,5,6}, while b=[01010101] represents the collection b={0,2,4,6} so that we can use |,& correspondence and, intersection, to set operation. such as A&b=[01000001],a b={0,6}.   bit arithmetic  Mask OperationsFirst there is a mask such as 0xFF, this mask can be considered a 8-bit binary, and each bit is 1Now there is a 16 binary number aa&0xff, this expression means that a becomes binary retains the last 8 bits of the value, the front becomes 0, is actually the binary each corresponding to do Boolean operations. logical operation of C languagetrue in logical operation is any nonzero, false is 0Expression result!0x41 0x00!0x00 0x01!! 0x41 0x010x69 && 0x55 0x010x69 | | 0x55 0x01 C language Shift operationsThe general machine supports two right-shift operations:Logical Right Shift: Move right, discard right, left end 0Arithmetic Right Shift:move right, discard right side, left end to fill the value of the most significant bitlike[01100011]>>4 result is [00000110]             [10010101]>>4 The result is[11111001]//Red 1 is the most significant bitNoteFor unsigned data must be logically right for the signed data, two can be, but there are portability problems, but almost all machines with arithmetic right shift Java x>>k is arithmetic right shift, x>>>k is the logical right shift for the W-bit number, the shift K-bit to him, The final displacement is the K mod w,c language, which avoids large numbers of displacements in this way.priority of the displacement OperationYou don't have to take that extra parenthesis.     

"In-depth understanding of computer systems" 2.1 Information storage

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.