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

Table of contents:

Representation of numbers in a computer. Representation of integers and real numbers in computer memory
Representation of numbers in a computer. Representation of integers and real numbers in computer memory
Anonim

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.

representation of numbers in a computer
representation of numbers in a computer

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.

representation of real numbers in a computer
representation of real numbers in a computer

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 × 27 + 1 × 2 6 + 1 ×25 + 1 × 24 + 1 × 23 + 1 × 2 2 + 1 × 21 + 1 × 20 =1 × 28- 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.

representation of numbers in computer memory
representation of numbers in computer memory

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.

computer representation of integers
computer representation of integers

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.

  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 bit of memory is inverted. To do this, all units are replaced by zeros and vice versa.
  3. 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.

Xmax=2 147 483 647.

Хmin=- 2 147 483 648.

representation of integers in computer memory
representation of integers in computer memory

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=11111112 =12710. Based on it, we can get the maximum size of a number that can be stored in the computer's memory. X=2127. Now we can calculate the maximum possible mantissa. It will be equal to 223 – 1 ≧ 223 =2(10 × 2, 3) ≧ 10002, 3 =10(3 × 2, 3) ≧ 107. 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.

representation of integers and real numbers in a computer
representation of integers and real numbers in a computer

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=11111111112 =102310.

M=252 -1=2(105.2) =10005.2 =1015.6. Rounding inthe larger side and get the maximum number X=21023accurate 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.

Popular topic

Editor's choice

  • How to block a person in "Contact"? Protect your page from ill-wishers
    How to block a person in "Contact"? Protect your page from ill-wishers

    The popularity of social networks is increasing every day. This is due to the fact that such an instrument of mass communication has entered everyday life and firmly established itself in it, as one of the most convenient ways of communication. Almost every advanced person has his own page on the social network, where he posts his photos, posts posts and, most importantly, communicates with friends and makes new acquaintances

  • Why doesn't "VK" work? The VKontakte website is not working: what to do?
    Why doesn't "VK" work? The VKontakte website is not working: what to do?

    Social media addiction is considered one of the most serious cyber diseases. Every day, tens of millions of users around the globe visit their personal accounts, chatting with friends, discussing the latest events in the world. Social networks have become such a dense part of our lives that it seems unusual to spend a day without looking at them even for a second

  • What is button accordion? Learn slang online
    What is button accordion? Learn slang online

    The Internet is a territory with its own rules, language, style of communication, and, more recently, laws. It so happened that many new users may be left at a loss after communicating with hardened Internet - "hacks". We are talking, first of all, about the use of slang by the latter in their language, which is far from accessible to everyone who opened the page of any forum for the first time

  • Hashtag - what is it? How to use hashtags
    Hashtag - what is it? How to use hashtags

    The Internet is constantly progressing, and every day new features appear in it that make working on it more convenient. They are associated, as a rule, with the optimization and structuring of information, since there is such a large amount of it on the World Wide Web that it is sometimes difficult to find the necessary material. For example, in the recent past, so-called hashtags appeared

  • Why is the internet slow? The most important reasons
    Why is the internet slow? The most important reasons

    In the last couple of years, the Internet has become an important part of the life of almost every person. Using the World Wide Web, we can find out the weather, the latest world news, download the necessary programs, play online games, etc. When the Internet is working well, doing the above things is very nice, but what if all of a sudden web pages start to load for a very long time, and online games slow down?