How to convert from the ternary system to decimal. Number systems. Transfer from one system to another

The shortest number system is binary. She is completely based on positional form recording numbers. The main characteristic is the principle doubling digits when performing a transition from a certain position to the next. You can convert from one number system to another either using a special program or manually.

In contact with

Historical recognition

The appearance of binary SS in history is associated with the scientist mathematician V.G. Leibniz. It was he who first spoke about the rules for performing operations with numerical values ​​of this kind. But initially this principle remained unclaimed. The algorithm received worldwide recognition and application at the dawn of computers.

Convenience and simplicity performing operations led to the need for a more detailed study of this subsection of arithmetic, which became indispensable in the development of computer technology with software. For the first time, such mechanisms appeared on the German and French markets.

Attention! A specific point about the superiority of the binary system in relation to the decimal system, precisely in this industry, was set in 1946 and substantiated in an article by A. Bex, H. Goldstein and J. Von Neumann.

Converting a number from the decimal number system to binary.

Features of binary arithmetic

All binary CC is based on the application of only two characters, which very closely match the features of the digital circuit. Each of the symbols is responsible for a specific action, which often implies two states:

  • the presence or absence of a hole, for example, a punched card or paper tape;
  • on magnetic media is responsible for the state of magnetization or demagnetization;
  • by signal level, high or low.

In the science in which SS is used, a certain terminology has been introduced, its essence is as follows:

  • Bit – binary digit, which consists of two components that carry a certain meaning. Placed on the left is defined as the senior one and is a priority, and on the right is the junior one, which is less significant.
  • A byte is a unit that consists of eight bits.

Many modules perceive and process information in portions or words. Each word has a different weight and can consist of 8, 16 or 32 bits.

Rules for transfers from one system to another

One of the most important factors in machine arithmetic is transfer from one SS to another. Therefore, let us pay attention to the basic algorithms for performing a process that will show how to convert a number to the binary system.

Converting the decimal system to binary

First, let's turn to the question of how to convert the system from decimal to binary number system. For this there is translation rule from decimal numbers to binary code, which implies mathematical operations.

Requires a number written in decimal form divide by 2. Continue dividing until there are no more in the quotient. unit. If a binary number system is required, the translation is carried out as follows:

186:2=93 (remaining 0)

93:2=46 (rest 1)

46:2=23 (remaining 0)

23:2=11 (rest 1)

11:2=5 (remaining 1)

5:2=2 (rest.1)

After the division process is completed, then write one in the quotient and write all the remainders sequentially in reverse order of division. That is, 18610=1111010. The rule for converting decimal numbers to SS must always be followed.

Converting a number from the decimal system to binary.

Converting from decimal SS to octal

A similar process is followed when converting from decimal SS to octal. It is also called " substitution rule" If in the previous example the data was divided by 2, then here it is necessary divide by 8. The algorithm for converting the number X10 to octal consists of the following steps:

  1. The number X10 begins to be divided by 8. We take the resulting quotient for the next division, and the remainder is written as least significant bit.
  2. We continue dividing until we get the result of the quotient equal zero or remainder, which in its value less than eight. In this case, we write all the remainders as low order bits.

For example, you need to convert the number 160110 to octal.

1601:8=200 (remaining 1)

200:8=25 (remaining 0)

25:8=3 (rest.1)

So, we get: 161010=31018.

Converting from decimal to octal.

Write a decimal number in hexadecimal

Conversion from decimal to hexadecimal SS is carried out similarly using the substitution system. But in addition to numbers, they also use letters of the latin alphabet A, B, C, D, E, F. Where A denotes the remainder 10, and F the remainder 15. The decimal number is divided by 16. For example, convert 10710 to hexadecimal:

107:16=6 (remaining 11 – replace B)

6 is less than sixteen. We stop dividing and write 10710 = 6B16.

Moving from another system to binary

The next question is how to convert a number from octal to binary. Converting numbers from any system to binary is quite simple. An assistant in this matter is table for number systems.

The positional number system first appeared in ancient Babylon. In India the system works as

positional decimal numbering using zero, the Indians have this number system

the Arab nation borrowed, and the Europeans, in turn, took from them. In Europe this system became

call it Arabic.

Positional system - the meaning of all digits depends on the position (digit) of a given digit in a number.

Examples, the standard 10th number system is a positional system. Let's say the number 453 is given.

The number 4 denotes hundreds and corresponds to the number 400, 5 - the number of tens and corresponds to the value 50,

and 3 - units and the value 3. It is easy to notice that as the digit increases, the value increases.

Thus, we write the given number as the sum 400+50+3=453.

Binary number system.

There are only 2 digits here - 0 and 1. Base of the binary system- number 2.

The number located at the very edge to the right indicates the number of units, the second number indicates

In all digits, only one digit is possible - either zero or one.

Using the binary number system, it is possible to encode any natural number by representing

This number is a sequence of zeros and ones.

Example: 10112 = 1*2 3 + 0*2*2+1*2 1 +1*2 0 =1*8 + 1*2+1=1110

The binary number system, like the decimal number system, is often used in computing

technology. The computer stores text and numbers in its memory in binary code and converts it programmatically

into the image on the screen.

Adding, subtracting and multiplying binary numbers.

Addition table in binary number system:

10 (transfer to

senior rank)

Subtraction table in binary number system:

(loan from senior

category) 1

Example of column addition (14 10 + 5 10 = 19 10 or 1110 2 + 101 2 = 10011 2):

+ 1 1 1 0
1 0 1
1 0 0 1 1

Multiplication table in binary number system:

Example of column multiplication (14 10 * 5 10 = 70 10 or 1110 2 * 101 2 = 1000110 2):

* 1 1 1 0
1 0 1
+ 1 1 1 0
1 1 1 0
= 1 0 0 0 1 1 0

Number conversion in the binary number system.

To convert from binary to decimal use the following table of exponents

bases 2:

Starting with the digit one, each digit is multiplied by 2. The dot after 1 is called binary point.

Convert binary numbers to decimal.

Let there be a binary number 110001 2. To convert to decimal we write it as a sum by

ranks as follows:

1 * 2 5 + 1 * 2 4 + 0 * 2 3 + 0 * 2 2 + 0 * 2 1 + 1 * 2 0 = 49

A little different:

1 * 32 + 1 * 16 + 0 * 8 + 0 * 4 + 0 * 2 + 1 * 1 = 49

It's also good to write the calculation as a table:

We move from right to left. Under all binary units we write its equivalent in the line below.

Convert fractional binary numbers to decimal numbers.

Exercise: convert the number 1011010, 101 2 to the decimal system.

We write the given number in this form:

1*2 6 +0*2 5 +1*2 4 +1*2 3 +0 *2 2 + 1 * 2 1 + 0 * 2 0 + 1 * 2 -1 + 0 * 2 -2 + 1 * 2 -3 = 90,625

Another recording option:

1*64+0*32+1*16+1*8+0*4+1*2+0*1+1*0,5+0*0,25+1*0,125 = 90,625

Or in table form:

0.25

0.125

0.125

Convert decimal numbers to binary.

Suppose you need to convert the number 19 to binary. We can do it this way:

19 /2 = 9 with the remainder 1

9 /2 = 4 with remainder 1

4 /2 = 2 without a trace 0

2 /2 = 1 without a trace 0

1 /2 = 0 with the remainder 1

That is, each quotient is divided by 2 and the remainder is written to the end of the binary notation. Division

continues until there is no zero in the quotient. We write the result from right to left. Those. lower

number (1) will be the leftmost one and so on. So, we have the number 19 in binary notation: 10011.

Converting fractional decimal numbers to binary.

When a given number contains an integer part, it is converted separately from the fractional part. Translation

converting a fractional number from the decimal number system to the binary system occurs as follows:

  • The fraction is multiplied by the base of the binary number system (2);
  • In the resulting product, an entire part is isolated, which is taken as the leading part.

digit of a number in the binary number system;

  • The algorithm terminates if the fractional part of the resulting product is zero or if

the required calculation accuracy has been achieved. Otherwise, calculations continue over

fractional part of the product.

Example: You need to convert the fractional decimal number 206.116 into a fractional binary number.

Translating the whole part, we get 206 10 =11001110 2. The fractional part of 0.116 is multiplied by base 2,

We put the whole parts of the product in the decimal places:

0,116 . 2 = 0,232

0,232 . 2 = 0,464

0,464 . 2 = 0,928

0,928 . 2 = 1,856

0,856 . 2 = 1,712

0,712 . 2 = 1,424

0,424 . 2 = 0,848

0,848 . 2 = 1,696

0,696 . 2 = 1,392

0,392 . 2 = 0,784

Result: 206,116 10 ≈ 11001110,0001110110 2

An algorithm for converting numbers from one number system to another.

1. From the decimal number system:

  • divide the number by the base of the translated number system;
  • find the remainder when dividing the integer part of a number;
  • write down all remainders from division in reverse order;

2. From the binary number system:

  • to convert to the decimal number system, we find the sum of the products of base 2 by

appropriate degree of discharge;

Write the number in the binary number system, and the powers of two from right to left. For example, we want to convert the binary number 10011011 2 to decimal. Let's write it down first. Then we write the powers of two from right to left. Let's start with 2 0, which is equal to "1". We increase the degree by one for each subsequent number. We stop when the number of elements in the list is equal to the number of digits in the binary number. Our example number, 10011011, has eight digits, so a list of eight elements would look like this: 128, 64, 32, 16, 8, 4, 2, 1

Write the digits of the binary number under the corresponding powers of two. Now simply write 10011011 under the numbers 128, 64, 32, 16, 8, 4, 2, and 1, so that each binary digit corresponds to a different power of two. The rightmost "1" of the binary number must correspond to the rightmost "1" of the powers of two, and so on. If you prefer, you can write the binary number above powers of two. The most important thing is that they match each other.

Match the digits in a binary number with the corresponding powers of two. Draw lines (from right to left) that connect each successive digit of the binary number to the power of two above it. Start drawing lines by connecting the first digit of a binary number to the first power of two above it. Then draw a line from the second digit of the binary number to the second power of two. Continue connecting each number to the corresponding power of two. This will help you visually see the relationship between two different sets of numbers.

Write down the final value of each power of two. Go through each digit of a binary number. If the number is 1, write the corresponding power of two under the number. If this number is 0, write 0 under the number.

  • Since "1" matches "1", it remains "1". Since "2" matches "1", it remains "2". Since "4" corresponds to "0", it becomes "0". Since "8" matches "1", it becomes "8", and since "16" matches "1" it becomes "16". "32" matches "0" and becomes "0", "64" matches "0" and therefore becomes "0", while "128" matches "1" and therefore becomes 128.
  • Add up the resulting values. Now add the resulting numbers under the line. Here's what you have to do: 128 + 0 + 0 + 16 + 8 + 0 + 2 + 1 = 155. This is the decimal equivalent of the binary number 10011011.

    Write the answer together with a subscript equal to the number system. Now all you have to do is write 155 10 to show that you are working with a decimal answer, which deals with powers of ten. The more you convert binary numbers to decimals, the easier it will be for you to remember powers of two, and the faster you will be able to complete the task.

  • Use this method to convert a binary number with a decimal point to decimal form. You can use this method even if you want to convert a binary number such as 1.1 2 to decimal. All you need to know is that the number on the left side of the decimal is a regular number, and the number on the right side of the decimal is the "halve" number, or 1 x (1/2).

    • "1" to the left of the decimal number corresponds to 2 0, or 1. 1 to the right of the decimal number corresponds to 2 -1, or.5. Add 1 and .5 and you get 1.5, which is the decimal equivalent of 1.1 2.
  • Hello, site visitor! We continue to study the IP network layer protocol, and to be more precise, its version IPv4. At first glance the topic binary numbers and binary number system has nothing to do with the IP protocol, but if we remember that computers work with zeros and ones, then it turns out that the binary system and its understanding is the basis of the fundamentals, we need learn to convert numbers from binary to decimal and vice versa: decimal to binary. This will help us better understand the IP protocol, as well as the principle of operation of variable-length network masks. Let's get started!

    If the topic of computer networks is interesting to you, you can read other course recordings.

    4.4.1 Introduction

    Before we begin, it’s worth explaining why a network engineer needs this topic. Although you could be convinced of its necessity when we spoke, you can say that there are IP calculators that greatly facilitate the task of allocating IP addresses, calculating the necessary subnet/network masks and determining the network number and host number in the IP address. That’s right, but the IP calculator is not always at hand, this is the reason number one. Reason number two is that in the Cisco exams they won't give you an IP calculator and that's it. you will have to do the conversion of IP addresses from decimal to binary on a piece of paper, and there are not so few questions where this is required in the exam/exams for obtaining the CCNA certificate, it would be a shame if the exam was failed because of such a trifle. And finally, understanding the binary number system leads to a better understanding of the principle of operation.

    In general, a network engineer is not required to be able to convert numbers from binary to decimal and vice versa in his head. Moreover, rarely anyone knows how to do this mentally; teachers of various courses on computer networks mainly fall into this category, since they constantly encounter this every day. But with a piece of paper and a pen, you should learn how to translate.

    4.4.2 Decimal digits and numbers, digits in numbers

    Let's start simple and talk about binary digits and numbers, you know that numbers and numbers are two different things. A number is a special symbol for designation, and a number is an abstract notation for quantity. For example, to write down that we have five fingers on our hand, we can use Roman and Arabic numerals: V and 5. In in this case five is both a number and a digit. And, for example, to write the number 20 we use two digits: 2 and 0.

    In total, in the decimal number system we have ten digits or ten symbols (0,1,2,3,4,5,6,7,8,9), by combining which we can write different numbers. What principle are we guided by when using the decimal number system? Yes, everything is very simple, we raise ten to one degree or another, for example, let’s take the number 321. How can it be written differently, like this: 3*10 2 +2*10 1 +1*10 0 . Thus, it turns out that the number 321 represents three digits:

    1. The number 3 means the most significant place or in this case it is the hundreds place, otherwise their number.
    2. The number 2 is in the tens place, we have two tens.
    3. The number one refers to the least significant digit.

    That is, in this entry a two is not just a two, but two tens or two times ten. And three is not just three, but three times a hundred. The following dependence is obtained: the unit of each next digit is ten times greater than the unit of the previous one, because what 300 is is three times a hundred. A digression regarding the decimal number system was necessary to make it easier to understand the binary system.

    4.4.3 Binary digits and numbers, as well as their recording

    There are only two digits in the binary number system: 0 and 1. Therefore, writing a number in the binary system is often much larger than in the decimal system. With the exception of the numbers 0 and 1, zero in the binary number system is equal to zero in the decimal number system, and the same is true for one. Sometimes, in order not to confuse which number system the number is written in, sub-indices are used: 267 10, 10100 12, 4712 8. The number in the sub-index indicates the number system.

    The symbols 0b and &(ampersand) can be used to write binary numbers: 0b10111, &111. If in the decimal number system, to pronounce the number 245 we use this construction: two hundred and forty-five, then in the binary number system, to name the number, we need to pronounce a digit from each digit, for example, the number 1100 in the binary number system should not be pronounced as a thousand one hundred, but like one, one, zero, zero. Let's look at writing the numbers from 0 to 10 in the binary number system:

    I think the logic should be clear by now. If in the decimal number system for each digit we had ten options available (from 0 to 9 inclusive), then in the binary number system in each of the digits of a binary number we have only two options: 0 or 1.

    To work with IP addresses and subnet masks, we only need natural numbers in the binary number system, although the binary system allows us to write fractional and negative numbers, but we don’t need this.

    4.4.4 Converting numbers from decimal to binary

    Let's take a better look at this how to convert a number from decimal to binary. And here everything is actually very, very simple, although it’s difficult to explain in words, so I’ll give it right away example of converting numbers from decimal to binary. Let's take the number 61, to convert to the binary system, we need to divide this number by two and see what is the remainder of the division. And the result of division is again divided by two. In this case, 61 is the dividend, we will always have two as a divisor, and we divide the quotient (the result of division) by two again, continue dividing until the quotient contains 1, this last unit will be the leftmost digit . The picture below demonstrates this.

    Please note that the number 61 is not 101111, but 111101, that is, we write the result from the end. In the latter particular, there is no sense in dividing one by two, since in this case integer division is used, and with this approach it turns out as in Figure 4.4.2.

    This is not the fastest way to convert a number from binary to decimal.. We have several accelerators. For example, the number 7 in binary is written as 111, the number 3 as 11, and the number 255 as 11111111. All these cases are incredibly simple. The fact is that the numbers 8, 4, and 256 are powers of two, and the numbers 7, 3, and 255 are one less than these numbers. So, for numbers that are one less than a number equal to a power of two, a simple rule applies: in the binary system, such a decimal number is written as a number of units equal to a power of two. So, for example, the number 256 is two to the eighth power, therefore, 255 is written as 11111111, and the number 8 is two to the third power, and this tells us that 7 in the binary number system will be written as 111. Well, understand, how to write 256, 4 and 8 in the binary number system is also not difficult, just add one: 256 = 11111111 + 1 = 100000000; 8 = 111 + 1 = 1000; 4 = 11 + 1 = 100.
    You can check any of your results on a calculator and it’s better to do so at first.

    As you can see, we have not yet forgotten how to divide. And now we can move on.

    4.4.5 Converting numbers from binary to decimal

    Converting numbers from binary is much easier than converting from decimal to binary. As an example of translation, we will use the number 11110. Pay attention to the table below, it shows the power to which you need to raise two in order to eventually get a decimal number.

    To get a decimal number from this binary number, you need to multiply each number in the digit by two to the power, and then add the results of the multiplication, it’s easier to show:

    1*2 4 +1*2 3 +1*2 2 +1*2 1 +0*2 0 = 16+8+4+2+0=30

    Let's open the calculator and make sure that 30 in the decimal number system is 11110 in binary.

    We see that everything was done correctly. From the example it is clear that Converting a number from binary to decimal is much easier than converting it back. To work with confidence you just need to remember powers of two up to 2 8. For clarity, I will provide a table.

    We don’t need more, since the maximum possible number that can be written in one byte (8 bits or eight binary values) is 255, that is, in each octet of the IP address or IPv4 subnet mask, the maximum possible value is 255. There are fields , in which there are values ​​greater than 255, but we do not need to calculate them.

    4.4.6 Addition, subtraction, multiplication of binary numbers and other operations with binary numbers

    Let's now look at operations that can be performed on binary numbers. Let's start with simple arithmetic operations and then move on to Boolean algebra operations.

    Adding binary numbers

    Adding binary numbers is not that difficult: 1+0 =1; 1+1=0 (I’ll give an explanation later); 0+0=0. These were simple examples where only one digit was used, let's look at examples where the number of digits is more than one.
    101+1101 in the decimal system is 5 + 13 = 18. Let's count in a column.

    The result is highlighted in orange, the calculator says that we calculated correctly, you can check it. Now let's see why this happened, because at first I wrote that 1+1=0, but this is for the case when we have only one digit, for cases when there are more than one digits, 1+1=10 (or two in decimal), which is logical.

    Then look what happens, we perform additions by digits from right to left:

    1. 1+1=10, write zero, and one goes to the next digit.

    2. In the next digit we get 0+0+1=1 (this unit came to us from the result of addition in step 1).

    4. Here we have a unit only in the second number, but it has also been transferred here, so 0+1+1 = 10.

    5. Glue everything together: 10|0|1|0.

    If you’re lazy in a column, then let’s count like this: 101011+11011 or 43 + 27 = 70. What can we do here, but let’s look, because no one forbids us to make transformations, and changing the places of the terms does not change the sum, for the binary number system this rule is also relevant.

    1. 101011 = 101000 + 11 = 101000 + 10 + 1 = 100000 + 1000 + 10 + 1.
    2. 11011 = 11000 + 10 + 1 = 10000 + 1000 + 10 + 1.
    3. 100000 + 10000 + (1000 +1000) + (10+10) + (1+1).
    4. 100000 + (10000 + 10000) + 100 + 10.
    5. 100000 + 100000 +110
    6. 1000000 + 110.
    7. 1000110.

    You can check with a calculator, 1000110 in binary is 70 in decimal.

    Subtracting Binary Numbers

    Immediately an example for subtracting single-digit numbers in the binary number system, we didn’t talk about negative numbers, so we don’t take 0-1 into account: 1 – 0 = 1; 0 – 0 = 0; 1 – 1 = 0. If there is more than one digit, then everything is also simple, you don’t even need any columns or tricks: 110111 – 1000, this is the same as 55 – 8. As a result, we get 101111. And the heart stopped beating , where does the unit in the third digit come from (numbering from left to right and starting from zero)? It's simple! In the second digit of the number 110111 there is 0, and in the first digit there is 1 (if we assume that the numbering of digits starts from 0 and goes from left to right), but the unit of the fourth digit is obtained by adding two units of the third digit (you get a kind of virtual two) and from this For twos, we subtract one, which is in the zero digit of the number 1000, and 2 - 1 = 1, and 1 is a valid digit in the binary number system.

    Multiplying binary numbers

    It remains for us to consider the multiplication of binary numbers, which is implemented by shifting one bit to the left. But first, let's look at the results of single-digit multiplication: 1*1 = 1; 1*0=0 0*0=0. Actually, everything is simple, now let's look at something more complex. Let's take the numbers 101001 (41) and 1100 (12). We will multiply by column.

    If it is not clear from the table how this happened, then I will try to explain in words:

    1. It is convenient to multiply binary numbers in a column, so we write out the second factor under the first; if the numbers have different numbers of digits, it will be more convenient if the larger number is on top.
    2. The next step is to multiply all the digits of the first number by the lowest digit of the second number. We write the result of the multiplication below; we need to write it so that under each corresponding digit the result of the multiplication is written.
    3. Now we need to multiply all the digits of the first number by the next digit of the second number and write the result one more line below, but this result needs to be shifted one digit to the left; if you look at the table, this is the second sequence of zeros from the top.
    4. The same must be done for subsequent digits, each time moving one digit to the left, and if you look at the table, you can say that one cell to the left.
    5. We have four binary numbers that we now need to add and get the result. We recently looked at addition, there shouldn't be any problems.

    In general, the multiplication operation is not that difficult, you just need a little practice.

    Boolean algebra operations

    There are two very important concepts in Boolean algebra: true and false, the equivalent of which is zero and one in the binary number system. Boolean algebra operators expand the number of available operators over these values, let's take a look at them.

    Logical AND or AND operation

    The Logical AND or AND operation is equivalent to multiplying single-digit binary numbers.

    1 AND 1 = 1; 1 AND 0 = 1; 0 AND 0 = 0; 0 AND 1 = 0.

    1 AND 1 = 1 ;

    1 AND 0 = 1 ;

    0 AND 0 = 0 ;

    0 AND 1 = 0.

    The result of “Logical AND” will be one only if both values ​​are equal to one; in all other cases it will be zero.

    Operation "Logical OR" or OR

    The operation “Logical OR” or OR works on the following principle: if at least one value is equal to one, then the result will be one.

    1 OR 1 = 1; 1 OR 0 = 1; 0 OR 1 = 1; 0 OR 0 = 0.

    1 OR 1 = 1 ;

    1 OR 0 = 1 ;

    0 OR 1 = 1 ;

    0 OR 0 = 0.

    Exclusive OR or XOR operation

    The operation "Exclusive OR" or XOR will give us a result of one only if one of the operands is equal to one and the second is equal to zero. If both operands are equal to zero, the result will be zero and even if both operands are equal to one, the result will be zero.

    The result has already been received!

    Number systems

    There are positional and non-positional number systems. The Arabic number system, which we use in everyday life, is positional, but the Roman number system is not. In positional number systems, the position of a number uniquely determines the magnitude of the number. Let's consider this using the example of the number 6372 in the decimal number system. Let's number this number from right to left starting from zero:

    Then the number 6372 can be represented as follows:

    6372=6000+300+70+2 =6·10 3 +3·10 2 +7·10 1 +2·10 0 .

    The number 10 determines the number system (in this case it is 10). The values ​​of the position of a given number are taken as powers.

    Consider the real decimal number 1287.923. Let's number it starting from zero position of the number from the decimal point to the left and right:

    Then the number 1287.923 can be represented as:

    1287.923 =1000+200+80 +7+0.9+0.02+0.003 = 1·10 3 +2·10 2 +8·10 1 +7·10 0 +9·10 -1 +2·10 -2 +3· 10 -3.

    In general, the formula can be represented as follows:

    C n s n +C n-1 · s n-1 +...+C 1 · s 1 +C 0 ·s 0 +D -1 ·s -1 +D -2 ·s -2 +...+D -k ·s -k

    where C n is an integer in position n, D -k - fractional number in position (-k), s- number system.

    A few words about number systems. A number in the decimal number system consists of many digits (0,1,2,3,4,5,6,7,8,9), in the octal number system it consists of many digits (0,1, 2,3,4,5,6,7), in the binary number system - from a set of digits (0,1), in the hexadecimal number system - from a set of digits (0,1,2,3,4,5,6, 7,8,9,A,B,C,D,E,F), where A,B,C,D,E,F correspond to the numbers 10,11,12,13,14,15. In the table Tab.1 numbers are presented in different number systems.

    Table 1
    Notation
    10 2 8 16
    0 0 0 0
    1 1 1 1
    2 10 2 2
    3 11 3 3
    4 100 4 4
    5 101 5 5
    6 110 6 6
    7 111 7 7
    8 1000 10 8
    9 1001 11 9
    10 1010 12 A
    11 1011 13 B
    12 1100 14 C
    13 1101 15 D
    14 1110 16 E
    15 1111 17 F

    Converting numbers from one number system to another

    To convert numbers from one number system to another, the easiest way is to first convert the number to the decimal number system, and then convert from the decimal number system to the required number system.

    Converting numbers from any number system to the decimal number system

    Using formula (1), you can convert numbers from any number system to the decimal number system.

    Example 1. Convert the number 1011101.001 from binary number system (SS) to decimal SS. Solution:

    1 ·2 6 +0 ·2 5 + 1 ·2 4 + 1 ·2 3 + 1 ·2 2 + 0 ·2 1 + 1 ·2 0 + 0 ·2 -1 + 0 ·2 -2 + 1 ·2 -3 =64+16+8+4+1+1/8=93.125

    Example2. Convert the number 1011101.001 from octal number system (SS) to decimal SS. Solution:

    Example 3 . Convert the number AB572.CDF from hexadecimal number system to decimal SS. Solution:

    Here A-replaced by 10, B- at 11, C- at 12, F- by 15.

    Converting numbers from the decimal number system to another number system

    To convert numbers from the decimal number system to another number system, you need to convert the integer part of the number and the fractional part of the number separately.

    The integer part of a number is converted from decimal SS to another number system by sequentially dividing the integer part of the number by the base of the number system (for binary SS - by 2, for 8-ary SS - by 8, for 16-ary SS - by 16, etc. ) until a whole residue is obtained, less than the base CC.

    Example 4 . Let's convert the number 159 from decimal SS to binary SS:

    159 2
    158 79 2
    1 78 39 2
    1 38 19 2
    1 18 9 2
    1 8 4 2
    1 4 2 2
    0 2 1
    0

    As can be seen from Fig. 1, the number 159 when divided by 2 gives the quotient 79 and remainder 1. Further, the number 79 when divided by 2 gives the quotient 39 and remainder 1, etc. As a result, constructing a number from division remainders (from right to left), we obtain a number in binary SS: 10011111 . Therefore we can write:

    159 10 =10011111 2 .

    Example 5 . Let's convert the number 615 from decimal SS to octal SS.

    615 8
    608 76 8
    7 72 9 8
    4 8 1
    1

    When converting a number from a decimal SS to an octal SS, you need to sequentially divide the number by 8 until you get an integer remainder less than 8. As a result, constructing a number from division remainders (from right to left) we get a number in an octal SS: 1147 (See Fig. 2). Therefore we can write:

    615 10 =1147 8 .

    Example 6 . Let's convert the number 19673 from the decimal number system to hexadecimal SS.

    19673 16
    19664 1229 16
    9 1216 76 16
    13 64 4
    12

    As can be seen from Figure 3, by successively dividing the number 19673 by 16, the remainders are 4, 12, 13, 9. In the hexadecimal number system, the number 12 corresponds to C, the number 13 to D. Therefore, our hexadecimal number is 4CD9.

    To convert regular decimal fractions (a real number with a zero integer part) into a number system with base s, it is necessary to sequentially multiply this number by s until the fractional part contains a pure zero, or we obtain the required number of digits. If, during multiplication, a number with an integer part other than zero is obtained, then this integer part is not taken into account (they are sequentially included in the result).

    Let's look at the above with examples.

    Example 7 . Let's convert the number 0.214 from the decimal number system to binary SS.

    0.214
    x 2
    0 0.428
    x 2
    0 0.856
    x 2
    1 0.712
    x 2
    1 0.424
    x 2
    0 0.848
    x 2
    1 0.696
    x 2
    1 0.392

    As can be seen from Fig. 4, the number 0.214 is sequentially multiplied by 2. If the result of multiplication is a number with an integer part other than zero, then the integer part is written separately (to the left of the number), and the number is written with a zero integer part. If the multiplication results in a number with a zero integer part, then a zero is written to the left of it. The multiplication process continues until the fractional part reaches a pure zero or we obtain the required number of digits. Writing bold numbers (Fig. 4) from top to bottom we get the required number in the binary number system: 0. 0011011 .

    Therefore we can write:

    0.214 10 =0.0011011 2 .

    Example 8 . Let's convert the number 0.125 from the decimal number system to binary SS.

    0.125
    x 2
    0 0.25
    x 2
    0 0.5
    x 2
    1 0.0

    To convert the number 0.125 from decimal SS to binary, this number is sequentially multiplied by 2. In the third stage, the result is 0. Consequently, the following result is obtained:

    0.125 10 =0.001 2 .

    Example 9 . Let's convert the number 0.214 from the decimal number system to hexadecimal SS.

    0.214
    x 16
    3 0.424
    x 16
    6 0.784
    x 16
    12 0.544
    x 16
    8 0.704
    x 16
    11 0.264
    x 16
    4 0.224

    Following examples 4 and 5, we get the numbers 3, 6, 12, 8, 11, 4. But in hexadecimal SS, the numbers 12 and 11 correspond to the numbers C and B. Therefore, we have:

    0.214 10 =0.36C8B4 16 .

    Example 10 . Let's convert the number 0.512 from the decimal number system to octal SS.

    0.512
    x 8
    4 0.096
    x 8
    0 0.768
    x 8
    6 0.144
    x 8
    1 0.152
    x 8
    1 0.216
    x 8
    1 0.728

    Got:

    0.512 10 =0.406111 8 .

    Example 11 . Let's convert the number 159.125 from the decimal number system to binary SS. To do this, we translate separately the integer part of the number (Example 4) and the fractional part of the number (Example 8). Further combining these results we get:

    159.125 10 =10011111.001 2 .

    Example 12 . Let's convert the number 19673.214 from the decimal number system to hexadecimal SS. To do this, we translate separately the integer part of the number (Example 6) and the fractional part of the number (Example 9). Further, combining these results we obtain.