ComputersInformation Technology

Representation of numbers in the computer. Representation of integers and real numbers in computer memory

Anyone who has ever thought about becoming an "IT person" or a system administrator, and simply connecting fate with computer technology, knowledge of how the representation of numbers in the memory of the computer is absolutely necessary. After all, this is the basis of low-level programming languages, such as Assembler. Therefore, today we will consider the representation of numbers in the computer and their placement in memory cells.

Notation

If you are reading this article, then, most likely, you already know about this, but it's worth repeating. All data in the personal computer is stored in a binary number system. This means that any number must be presented in an appropriate form, that is, consisting of zeros and ones.

To translate the usual for us decimal numbers to a kind, an understandable computer, you need to use the algorithm described below. There are also specialized calculators.

So, in order to translate a number into a binary number system, you need to take the value chosen by us and divide it by 2. After that, we get the result and the remainder (0 or 1). Result again divide 2 and remember the remainder. This procedure should be repeated until the result is also 0 or 1. Then write the final value and the residues in the reverse order, as we received them.

This is how the numbers are represented in the computer. Any number is written in binary form, and then occupies a memory location.

Memory

As you should already know, the minimum unit of information is 1 bit. As we have already seen, the representation of numbers in the computer is in binary format. Thus, each bit of memory will be occupied by a single value - 1 or 0.

To store large numbers , cells are used. Each such unit contains up to 8 bits of information. Therefore, we can conclude that the minimum value in each segment of memory can be 1 byte or be an eight-digit binary number.

Whole

Finally, we got to the direct placement of data in the computer. As it was already said, first of all the processor translates information into binary format, and only then places it in memory.

We'll start with the simplest version, which is the representation of integers in the computer. PC memory allocates this process to ridiculously small number of cells - only one. Thus, the maximum in one slot can be from 0 to 11111111. Let's translate the maximum number into the usual form of the record.
X = 1 × 2 7 + 1 × 2 6 + 1 × 2 5 + 1 × 2 4 + 1 × 2 3 + 1 × 2 2 + 1 × 2 1 + 1 × 2 0 = 1 × 2 8 - 1 = 255 .

Now we see that in one memory cell a value from 0 to 255 can be located. However, this only applies to non-negative integers. If the computer needs to write down a negative value, everything will go a little differently.

Negative numbers

Now let's see how the numbers are represented in the computer, if they are negative. To place a value that is less than zero, two memory cells or 16 bits of information are allocated. In this case, 15 goes under the number itself, and the first (extreme left) bit is given under the corresponding sign.

If the digit is negative, then "1" is written, if positive, then "0". For simplicity of remembering, we can draw an analogy: if there is a sign, then set 1, if it is not, then nothing (0).

The remaining 15 bits of information are assigned to a number. Similar to the previous case, they can put a maximum of fifteen units. It should be noted that the recording of negative and positive numbers is significantly different from each other.

In order to place a value in the 2 memory cells greater than zero or equal to it, the so-called direct code is used. This operation is performed in the same way as it was described, and the maximum A = 32766, if we use the decimal number system. Just want to note that in this case, "0" refers to the positive.

Examples

Representing integers in computer memory is not such a difficult task. Although it is slightly more complicated, if it is a negative meaning. To write a number that is less than zero, an additional code is used.

To get it, the machine performs a number of auxiliary operations.

  1. First, the modulus of a negative number is written in binary notation. That is, the computer remembers a similar but positive value.
  2. Then, each memory bit is inverted. To do this, all units are replaced by zeros and vice versa.
  3. Add "1" to the result. This will be an additional code.

Here is an illustrative example. Suppose we have the number X = -131. First we get its module | X | = 131. Then we translate it into a binary system and write it into 16 cells. We get X = 0000000010000011. After the inverting, X = 1111111101111100. Add to it "1" and get the reverse code X = 1111111101111101. To write to a 16-bit memory location, the minimum number is X = - (2 15 ) = - 32767.

Long integers

As you can see, the representation of real numbers in a computer is not so difficult. However, this range may not be enough for most operations. Therefore, in order to accommodate large numbers, the computer allocates from memory 4 cells, or 32 bits.

The process of recording does not differ from the one presented above. So we just give the range of numbers that can be stored in a given type.

X max = 2 147 483 647.

X min = - 2 147 483 648.

These values in most cases are enough to record and perform operations with data.

The representation of real numbers in a computer has its advantages and disadvantages. On the one hand, this technique makes it easier to perform operations between integer values, which significantly speeds up the processor. On the other hand, this range is not enough to solve most of the problems of economics, physics, arithmetic and other sciences. Therefore, now we will consider another technique for superuniverses.

Floating point

This is the last thing you need to know about the representation of numbers in a computer. Since when recording fractions there is a problem of determining the position of the comma in them, an exponential form is used to place such digits in the computer.

Any number can be represented in the following form X = m * p n . Where m is the mantissa of a number, p is the base of the number system and n is the order of the number.

To standardize the recording of floating-point numbers, the following condition is used, according to which the mantissa module must be greater than or equal to 1 / n and less than 1.

Suppose we are given a number of 666.66. Let us bring it to an exponential form. It turns out that X = 0.666666 * 10 3 . P = 10 and n = 3.

Floating-point values are usually stored with 4 or 8 bytes (32 or 64 bits). In the first case this is called the number of ordinary accuracy, and in the second case it is called double precision.

Of the 4 bytes allocated for storing the digits, 1 (8 bits) is given for data about the order and its sign, and 3 bytes (24 bits) are allocated for storing the mantissa and its sign according to the same principles as for integer values. Knowing this, we can make simple calculations.

The maximum value of n = 1111111 2 = 127 10 . Based on it, we can get the maximum size of a number that can be stored in the computer's memory. X = 2 127 . Now we can calculate the maximum possible mantissa. It will be equal to 2 23 - 1 ≥ 2 23 = 2 (10 × 2,3) ≥ 1000 2,3 = 10 (3 × 2,3) ≥ 10 7 . As a result, we obtained an approximate value.

If now we combine both calculations, we get a value that can be written without loss of 4 bytes of memory. It will be equal to X = 1.701411 * 10 38 . The remaining digits were discarded, since it is this precision that allows this method of recording.

Double precision

Since all the calculations were described and explained in the previous paragraph, here we will tell everything very briefly. For numbers with double precision, usually 11 bits are allocated for the order and its sign, as well as 53 bits for the mantissa.

П = 1111111111 2 = 1023 10 .

M = 2 52 -1 = 2 (10 * 5.2) = 1000 5.2 = 10 15.6 . We round to the larger side and get the maximum number X = 2 1023 to within "m".

We hope that the information about the representation of integers and real numbers in the computer that we provided is useful to you in training and will be at least a little more understandable than what is usually written in textbooks.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.atomiyme.com. Theme powered by WordPress.