For anyone who has ever thought about becoming an "IT specialist" or a system administrator, or just linking their fate with computer technology, knowing how numbers are represented in computer memory is absolutely necessary. After all, this is what low-level programming languages such as Assembler are based on. Therefore, today we will consider the representation of numbers in a computer and their placement in memory cells.

## Number system

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

To convert the decimal numbers familiar to us to a form understandable by a computer, you need to use the algorithm described below. There are also specialized calculators.

So, in order to convert a number to the binary number system, we need to take the value we have chosen and divide it by 2. After that, wewe get the result and the remainder (0 or 1). Divide the result by 2 again and store the remainder. This procedure must be repeated until the result also turns out to be 0 or 1. Then we write the final value and the remainders in the reverse order, as we received them.

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

## Memory

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

Cells are used to store large numbers. 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 already mentioned, the processor first converts information into binary format, and only then places it in memory.

We will start with the simplest option, which is the representation of integers in a computer. The PC memory allocates a ridiculously small number of cells for this process - just one. Thus, a maximum of one slot can contain values from 0 to 11111111. Let's translate the maximum number into our usual notation.

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 one memory cell can contain a value from 0 to 255. However, this only applies to non-negative integers. If the computer needs to write a negative value, things are a little different.

## Negative numbers

Now let's see how numbers are represented in a computer if they are negative. To accommodate 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 (leftmost) bit is given under the corresponding sign.

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

The remaining 15 bits of information are assigned to the number. Similar to the previous case, a maximum of fifteen units can be placed in them. It is worth noting that the writing of negative and positive numbers is significantly different from each other.

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

## Examples

Representing integers in computer memory is not such a difficult task. Although it gets a little more complicated when it comes to a negative value. An additional code is used to write a number that is less than zero.

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

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

Let's give an illustrative example. Suppose we have a number X=- 131. First, we get its modulus |X|=131. Then we convert it into binary system and write it into 16 cells. We get X \u003d 0000000010000011. After inverting, X \u003d 1111111101111100. We add "1" to it and get the return code X=1111111101111101. For writing to a 16-bit memory location, the minimum number is X=- (215)=- 32767.

## Long integers

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

The recording process is absolutely the same as above. So we'll just give a range of numbers,that can be stored in this type.

X_{max=2 147 483 647.}

Х_{min=- 2 147 483 648.}

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

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 problems in economics, physics, arithmetic, and other sciences. Therefore, now we will consider another technique for superquantities.

## Floating point

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

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

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

Let us be given the number 666, 66. Let's bring it to the exponential form. You get X=0.66666103. P=10 and n=3.

Floating point values are usually allocated 4 or 8 bytes (32 or 64 bits). ATin the first case it is called a regular precision number, and in the second case it is called a double precision number.

Out of 4 bytes allocated for storing numbers, 1 (8 bits) is given for data on the order and its sign, and 3 bytes (24 bits) go to store the mantissa and its sign according to the same principles as for integer values. Knowing this, we can do some simple calculations.

Max 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 got an approximate value.}

If we now combine both calculations, we get a value that can be written losslessly into 4 bytes of memory. It will be equal to X=1.7014111038. The rest of the numbers were discarded, since this notation allows for exactly this accuracy.

## Double precision

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

P=1111111111^{2} =1023^{10.}

M=2^{52} -1=2^{(105.2)} =1000^{5.2} =10^{15.6}. Rounding inthe larger side and get the maximum number X=2^{1023accurate to "m".}

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