• Binary number system translation of numbers examples. Converting numbers to binary, hexadecimal, decimal, octal number systems

    Those taking the Unified State Exam and more...

    It is strange that in computer science lessons in schools they usually show students the most complex and inconvenient way to convert numbers from one system to another. This method consists of sequentially dividing the original number by the base and collecting the remainders from the division in reverse order.

    For example, you need to convert the number 810 10 to binary:

    We write the result in reverse order from bottom to top. It turns out 81010 = 11001010102

    If you need to convert to the binary system, quite big numbers, then the division ladder takes on the size of a multi-story building. And how can you collect all the ones and zeros and not miss a single one?

    IN Unified State Exam program in computer science includes several tasks related to the translation of numbers from one system to another. Typically, this is a conversion between octal and hexadecimal systems and binary. These are sections A1, B11. But there are also problems with other number systems, such as in section B7.

    To begin with, let us recall two tables that would be good to know by heart for those who choose computer science as their future profession.

    Table of powers of number 2:

    2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10
    2 4 8 16 32 64 128 256 512 1024

    It is easily obtained by multiplying the previous number by 2. So, if you do not remember all of these numbers, the rest are not difficult to obtain in your mind from those that you remember.

    Table of binary numbers from 0 to 15 with hexadecimal representation:

    0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
    0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
    0 1 2 3 4 5 6 7 8 9 A B C D E F

    The missing values ​​are also easy to calculate by adding 1 to the known values.

    Integer conversion

    So, let's start by converting directly to the binary system. Let's take the same number 810 10. We need to decompose this number into terms equal to powers of two.

    1. We are looking for the power of two closest to 810 and not exceeding it. This is 2 9 = 512.
    2. Subtract 512 from 810, we get 298.
    3. Repeat steps 1 and 2 until there are no 1s or 0s left.
    4. We got it like this: 810 = 512 + 256 + 32 + 8 + 2 = 2 9 + 2 8 + 2 5 + 2 3 + 2 1.
    Then there are two methods, you can use any of them. How easy it is to see that in any number system its base is always 10. The square of the base will always be 100, the cube 1000. That is, the degree of the base of the number system is 1 (one), and there are as many zeros behind it as the degree is.

    Method 1: Arrange 1 according to the digits of the indicators of the terms. In our example, these are 9, 8, 5, 3 and 1. The remaining places will contain zeros. So, we got the binary representation of the number 810 10 = 1100101010 2. Units are placed in 9th, 8th, 5th, 3rd and 1st places, counting from right to left from zero.

    Method 2: Let's write the terms as powers of two under each other, starting with the largest.

    810 =

    Now let's add these steps together, like folding a fan: 1100101010.

    That's it. Along the way, the problem of “how many units in binary notation number 810?

    The answer is as many as there are terms (powers of two) in this representation. 810 has 5 of them.

    Now the example is simpler.

    Let's convert the number 63 to the 5-ary number system. The closest power of 5 to 63 is 25 (square 5). A cube (125) will already be a lot. That is, 63 lies between the square of 5 and the cube. Then we will select the coefficient for 5 2. This is 2.

    We get 63 10 = 50 + 13 = 50 + 10 + 3 = 2 * 5 2 + 2 * 5 + 3 = 223 5.

    And, finally, very easy translations between 8 and hexadecimal systems. Since their base is a power of two, the translation is done automatically, simply by replacing the numbers with their binary representation. For the octal system, each digit is replaced by three binary digits, and for the hexadecimal system, four. In this case, all leading zeros are required, except for the most significant digit.

    Let's convert the number 547 8 to binary.

    547 8 = 101 100 111
    5 4 7

    One more, for example 7D6A 16.

    7D6A 16 = (0)111 1101 0110 1010
    7 D 6 A

    Let's convert the number 7368 to the hexadecimal system. First, write the numbers in triplets, and then divide them into quadruples from the end: 736 8 = 111 011 110 = 1 1101 1110 = 1DE 16. Let's convert the number C25 16 to the octal system. First, we write the numbers in fours, and then divide them into threes from the end: C25 16 = 1100 0010 0101 = 110 000 100 101 = 6045 8. Now let's look at converting back to decimal. It is not difficult, the main thing is not to make mistakes in the calculations. We expand the number into a polynomial with powers of the base and coefficients for them. Then we multiply and add everything. E68 16 = 14 * 16 2 + 6 * 16 + 8 = 3688. 732 8 = 7 * 8 2 + 3*8 + 2 = 474 .

    Converting Negative Numbers

    Here you need to take into account that the number will be presented in additional code. To convert a number into additional code, you need to know the final size of the number, that is, what we want to fit it into - in a byte, in two bytes, in four. The most significant digit of a number means the sign. If there is 0, then the number is positive, if 1, then it is negative. On the left, the number is supplemented with a sign digit. We do not consider unsigned numbers; they are always positive, and the most significant bit in them is used as information.

    For translation negative number in binary's complement code you need to convert a positive number to binary, then change the zeros to ones and the ones to zeros. Then add 1 to the result.

    So, let's convert the number -79 to the binary system. The number will take us one byte.

    We convert 79 to the binary system, 79 = 1001111. We add zeros on the left to the size of the byte, 8 bits, we get 01001111. We change 1 to 0 and 0 to 1. We get 10110000. We add 1 to the result, we get the answer 10110001. Along the way, we answer the Unified State Exam question “how many units are in the binary representation of the number -79?” The answer is 4.

    Adding 1 to the inverse of a number eliminates the difference between the representations +0 = 00000000 and -0 = 11111111. In two's complement code they will be written the same as 00000000.

    Converting fractional numbers

    Fractional numbers are converted in the reverse way of dividing whole numbers by the base, which we looked at at the very beginning. That is, using sequential multiplication by a new base with the collection of whole parts. The integer parts obtained during multiplication are collected, but do not participate in the following operations. Only fractions are multiplied. If the original number is greater than 1, then the integer and fractional parts are translated separately and then glued together.

    Let's convert the number 0.6752 to the binary system.

    0 ,6752
    *2
    1 ,3504
    *2
    0 ,7008
    *2
    1 ,4016
    *2
    0 ,8032
    *2
    1 ,6064
    *2
    1 ,2128

    The process can be continued for a long time until we get all the zeros in the fractional part or the required accuracy is achieved. Let's stop at the 6th sign for now.

    It turns out 0.6752 = 0.101011.

    If the number was 5.6752, then in binary it will be 101.101011.

    The calculator allows you to convert whole and fractional numbers from one number system to another. The base of the number system cannot be less than 2 and greater than 36 (10 digits and 26 Latin letters after all). The length of numbers must not exceed 30 characters. To enter fractional numbers, use the symbol. or, . To convert a number from one system to another, enter the original number in the first field, the base of the original number system in the second, and the base of the number system to which you want to convert the number in the third field, then click the "Get Record" button.

    Original number written in 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 -th number system.

    I want to get a number written in 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 -th number system.

    Get entry

    Translations completed: 1363703

    Number systems

    Number systems are divided into two types: positional And not positional. We use the Arabic system, it is positional, but there is also the Roman system - it is not positional. IN positional systems The position of a digit in a number uniquely determines the value of that number. This is easy to understand by looking at some number as an example.

    Example 1. Let's take the number 5921 in the decimal number system. Let's number the number from right to left starting from zero:

    The number 5921 can be written in the following form: 5921 = 5000+900+20+1 = 5·10 3 +9·10 2 +2·10 1 +1·10 0 . The number 10 is a characteristic that defines the number system. The values ​​of the position of a given number are taken as powers.

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

    The number 1234.567 can be written in the following form: 1234.567 = 1000+200+30+4+0.5+0.06+0.007 = 1·10 3 +2·10 2 +3·10 1 +4·10 0 +5·10 -1 + 6·10 -2 +7·10 -3 .

    Converting numbers from one number system to another

    Most in a simple way converting a number from one number system to another is to first convert the number into a decimal number system, and then the resulting result into the required number system.

    Converting numbers from any number system to the decimal number system

    To convert a number from any number system to decimal, it is enough to number its digits, starting with zero (the digit to the left of the decimal point) similarly to examples 1 or 2. Let's find the sum of the products of the digits of the number by the base of the number system to the power of the position of this digit:

    1. Convert the number 1001101.1101 2 to the decimal number system.
    Solution: 10011.1101 2 = 1·2 4 +0·2 3 +0·2 2 +1·2 1 +1·2 0 +1·2 -1 +1·2 -2 +0·2 -3 +1·2 - 4 = 16+2+1+0.5+0.25+0.0625 = 19.8125 10
    Answer: 10011.1101 2 = 19.8125 10

    2. Convert the number E8F.2D 16 to the decimal number system.
    Solution: E8F.2D 16 = 14·16 2 +8·16 1 +15·16 0 +2·16 -1 +13·16 -2 = 3584+128+15+0.125+0.05078125 = 3727.17578125 10
    Answer: E8F.2D 16 = 3727.17578125 10

    Converting numbers from the decimal number system to another number system

    To convert numbers from decimal system When calculating numbers into another number system, the integer and fractional parts of a number must be converted separately.

    Converting an integer part of a number from a decimal number system to another number system

    An integer part is converted from a decimal number system to another number system by sequentially dividing the integer part of a number by the base of the number system until a whole remainder is obtained that is less than the base of the number system. The result of the translation will be a record of the remainder, starting with the last one.

    3. Convert the number 273 10 to the octal number system.
    Solution: 273 / 8 = 34 and remainder 1. 34 / 8 = 4 and remainder 2. 4 is less than 8, so the calculation is complete. The record from the balances will look like this: 421
    Examination: 4·8 2 +2·8 1 +1·8 0 = 256+16+1 = 273 = 273, the result is the same. This means the translation was done correctly.
    Answer: 273 10 = 421 8

    Let's consider the translation of regular decimal fractions into various number systems.

    Converting the fractional part of a number from the decimal number system to another number system

    Recall that a proper decimal fraction is called real number with zero integer part. To convert such a number to a number system with base N, you need to sequentially multiply the number by N until the fractional part is zeroed or the required number of digits is obtained. If, during multiplication, a number with an integer part other than zero is obtained, then the integer part is not taken into account further, since it is sequentially entered into the result.

    4. Convert the number 0.125 10 to the binary number system.
    Solution: 0.125·2 = 0.25 (0 is the integer part, which will become the first digit of the result), 0.25·2 = 0.5 (0 is the second digit of the result), 0.5·2 = 1.0 (1 is the third digit of the result, and since the fractional part is zero , then the translation is completed).
    Answer: 0.125 10 = 0.001 2

    Tags: Number system, number system translation, related number systems

    Changing the base for positional number systems

    In a positional number system with base q, a number can be represented as a polynomial

    … + a 2 ∙q 2 + a 1 q 1 + a 0 ∙q 0 + a -1 ∙q -1 + a -2 ∙q -2 + …

    where the coefficients a i are the digits of the number system with base q.

    For example, in the decimal number system

    124.733 = 1∙10 2 + 2∙10 1 + 4∙10 0 + 7∙10 -1 + 3∙10 -2 + 3∙10 -3

    The number of digits in a number system with base q is equal to q, and the maximum digit is q - 1. A digit cannot become equal to q, because in this case the unit will be transferred to a new digit.

    For example, you need to find the minimum base of the number system in which the number 7832 is written. Since the maximum digit is 8, then the minimum value is q = 8 + 1 = 9.

    The base of a number system can, in principle, be any number: integer, negative, rational, irrational, complex, etc. We will consider only positive integer bases.

    Of particular interest to us will be the base 2 and the bases that are powers of two - 8 and 16.

    In case the base with. With. more than ten, then new numbers are taken in order from the alphabet. For example, for the hexadecimal system these will be the numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.

    Converting the whole part of the decimal number system

    The first way to convert from the decimal number system to the n-ary number system is to sequentially divide the number by a new base.

    123/12 = 10 (3) 10/12 = 0 (10=A)

    We collect in reverse order, first the last value (this is 0), then from top to bottom all the remainders. We get 0A3 = A3

    4563/8 = 570 (3) 570/8 = 71 (2) 71/8 = 8 (7) 8/8 = 1 (0)

    Putting it back together, we get 10723

    3349 10 → X 16

    3349/16 = 209 (5) 209/16 = 13 (1) 13/16 = 0 (13 = D)

    Putting it together: 0D15 = D15

    545/2 = 272 (1) 272/2 = 136 (0) 136/2 = 68 (0) 68/2 = 34 (0) 34/2 = 17 (0) 17/2 = 8 (1) 8/2 = 4 (0) 4/2 = 2(0) 2/2 = 1 (0) 1/2 = 0(1)

    We collect 01000100001 = 1000100001

    Translation on paper is usually done by dividing into a column. Until the division results in zero, each subsequent answer is divided by the base c. With. At the end, the answer is collected from the remainders of the division.

    It is also often possible to convert a number to another s. With. , if we mentally imagine it as the sum of powers of the corresponding base into which we want to convert the number.

    For example, 129 is obvious 128 + 1 = 2 7 + 1 = 10000001 2

    80 = 81 - 1 = 3 4 - 1 = 10000 - 1 = 2222 3

    Converting an integer part to the decimal number system

    The translation is carried out using the representation of the number in the positional number system. Let it be necessary to translate A3 12 → X 10 It is known that A3 is 3∙q 0 + A∙q 1 , that is, 3*1 + A*12 = 3 + 120 = 123

    10723 8 → X 10

    1∙q 4 + 0∙q 3 + 7∙q 2 + 2∙q 1 + 3∙q 0 = 1∙8 4 + 0 + 7∙8 2 + 2∙8 + 3 = 1∙4096 + 7∙64 + 2∙8 + 3 = 4563

    D∙16 2 + 1∙16 1 +5∙16 0 = 13∙256 + 16 + 5 = 3349

    1000100001 2 → X 10

    2 9 + 2 5 + 1 = 512 + 32 + 1 = 545.

    Translation on paper is usually carried out as follows. The degree number is written in order above each number. Then all the terms are written out.

    Converting the fractional part from the decimal system

    When converting a fractional part, a situation often occurs when a finite decimal fraction turns into an infinite one. Therefore, usually when translating, the accuracy with which it is necessary to translate is indicated. The translation is carried out by sequentially multiplying the fractional part by the base of the number system. The whole part is folded back and becomes part of the fraction.

    0.625 10 → X 2

    0.625 * 2 = 1.250 (1) 0.25 * 2 = 0.5 (0) 0.5 * 2 = 1.0 (1)

    0 – further multiplication will produce only zeros
    Collecting from top to bottom, we get 0.101

    0.310 → X2 0.3 * 2 = 0.6 (0) 0.6 * 2 = 1.2 (1) 0.2 * 2 = 0.4 (0) 0.4 * 2 = 0.8 (0) 0.8 * 2 = 1.6 (1) 0.6 * 2 = 1.2 (1 )

    0.2 ... we get a periodic fraction
    We collect, we get 0.0100110011001... = 0.0(1001)

    0.64510 → X5 0.645 * 5 = 3.225 (3) 0.255 * 5 = 1.275 (1) 0.275 * 5 = 1.375 (1) 0.375 * 5 = 1.875 (1) 0.875 * 5 = 4.375 (4) 0.375 * 5 = 1.8 75 (1 ) ...

    0.3111414… = 0.311(14)

    Converting the fractional part to the decimal system

    It is carried out similarly to the translation of an integer part, by multiplying the digit of the digit by the base to a degree equal to the position of the digit in the number.

    0.101 2 → X 10

    1∙2 -1 + 0∙2 -2 + 1∙2 -3 = 0.5 + 0.125 = 0.625

    0.134 5 → X 10

    1∙5 -1 + 3∙5 -2 +4∙5 -3 = 0.2 + 3∙0.04 + 4∙0.008 = 0.2 + 0.12 + 0.032 = 0.352

    Transfer from an arbitrary number system to an arbitrary one

    Conversion from an arbitrary number system to an arbitrary number system. With. carried out using decimal s. With.

    X N → X M ≡ X N → X 10 → X M

    For example

    1221201 3 → X 7

    1221201 3 = 1∙3 6 + 2∙3 5 + 2∙3 4 + 1∙3 3 + 2∙3 2 + 1 = 729 + 2∙243 + 2∙81 + 27 + 9 + 1 = 1414 10

    1414/7 = 202 (0) 202/7 = 28 (6) 28/7 = 4 (0) 4/7 = 0 (4)

    1221201 3 → 4060 7

    Related number systems

    Number systems are called related when their bases are powers of the same number. For example, 2, 4, 8, 16. Translation between related number systems can be carried out using the table

    Table for conversion between related number systems with base 2
    10 2 4 8 16
    0 0000 000 00 0
    1 0001 001 01 1
    2 0010 002 02 2
    3 0011 003 03 3
    4 0100 010 04 4
    5 0101 011 05 5
    6 0110 012 06 6
    7 0111 013 07 7
    8 1000 020 10 8
    9 1001 021 11 9
    10 1010 022 12 A
    11 1011 023 13 B
    12 1100 030 14 C
    13 1101 031 15 D
    14 1110 032 16 E
    15 1111 033 17 F

    To convert from one related number system to another, you first need to convert the number to the binary system. To convert to the binary number system, each digit of a number is replaced by the corresponding two (for quaternary), three (for octal) or four (for hexadecimal).

    For 123 4, one is replaced by 01, two by 10, three by 11, we get 11011 2

    For 5721 8 respectively 101, 111, 010, 001, total 101111010001 2

    For E12 16 we get 111000010010 2

    To convert from the binary system, you need to break the number into twos (4th), triples (8th) or fours of numbers (16th), and then replace them with the corresponding values.

    When converting numbers from the decimal number system to any other, the whole and fractional parts are always translated separately (according to different rules).

    Translation of the whole part

    In order to convert a number from a decimal number system to any other, you need to perform integer division of the original number by the base of the number system to which you want to convert the number. In this case, the remainder of the division and the quotient are important. The quotient must be divided by the base until 0 remains. After this, all remainders must be written in reverse order - this will be the number in new system Reckoning.

    For example, converting the number 25 from the decimal number system to the binary system will look like this:

    Writing out the remainders in reverse order, we get 25 10 =11001 2.

    If you think about it, you can easily notice that when converting absolutely any number into the binary number system, the very last remainder (that is, the very first digit in the result) will always be equal to the very last quotient, which turned out to be less than the base of the number system in which we translate the number. Therefore, division is often stopped before the quotient becomes equal to zero - at the moment when the quotient becomes simply less than the base. For example:

    Conversion from the decimal number system to any other number system is carried out according to exactly the same rules. Here is an example of converting 393 10 to hexadecimal number system:

    Writing out the remainders in reverse order, we get 393 10 =189 16.

    You need to understand that the remainders are obtained in the decimal number system. When dividing by 16, residues may appear not only from 0 to 9, but also residues from 10 to 15. Each remainder is always exactly one digit in the number system into which the translation is made.

    For example, if, when converting to the hexadecimal number system, you received the following remainders (written out in the order they should be written in the number): 10, 3, 15, 7, then in the hexadecimal number system this sequence of remainders will correspond to the number A3F7 16 (some they mistakenly write the number as 103157 16 - it is clear that this is a completely different number, and that if you do this, it turns out that the numbers from A to F will not appear in any hexadecimal number).

    Fractional translation

    When translating a fractional part, in contrast to translating an entire part, you do not need to divide, but multiply by the base of the number system into which we are converting. In this case, whole parts are discarded each time, and fractional parts are multiplied again. By collecting the whole parts in the order in which they were obtained, we obtain the fractional part of the number in required system Reckoning.

    One multiplication operation gives exactly one additional sign in the number system into which the translation is carried out.

    In this case, there are two conditions for completing the process:

    1) as a result of the next multiplication you received a zero in the fractional part. It is clear that no matter how much you multiply this zero, it will still remain zero. This means that the number has been converted from the decimal number system to the required one exactly.

    2) not all numbers can be translated accurately. In this case, it is usually translated with some accuracy. In this case, they first determine how many decimal places will be needed - this is the number of times that the multiplication operation will need to be performed.

    Here is an example of converting the number 0.39 10 to the binary number system. Accuracy - 8 digits (in in this case translation accuracy is chosen arbitrarily):

    If we write out the whole parts in direct order, we get 0.39 10 =0.01100011 2 .

    There is no need to write out the very first zero (crossed out in blue in the figure) - since it refers not to the fractional part, but to the whole part. Some people mistakenly write this zero after the decimal point when writing out the result.

    This is what the conversion of the number 0.39 10 to hexadecimal number system will look like. Accuracy - 8 digits; in this case, the accuracy is again chosen arbitrarily:

    If we write out the whole parts in direct order, we get 0.39 10 =0.63D700A3 16.

    At the same time, you probably noticed that whole parts when multiplied are obtained in the decimal number system. These integer parts obtained when translating the fractional part of a number should be interpreted in exactly the same way as the remainders when translating the whole part of a number. That is, if, when converted to the hexadecimal number system, the integer parts were obtained in the following order: 3, 13, 7, 10, then the corresponding number will be equal to 0.3D7A 16 (and not 0.313710 16, as some sometimes erroneously write).

    Converting numbers with integer and fractional parts

    To translate a number with an integer and a fractional part, you need to translate the integer part separately, and the fractional part separately, and then write these two parts together.

    For example, 25.39 10 =11001.01100011 2 (translations of the integer and fractional parts - see above).

    Converting small integers from decimal to binary in your head

    Since when working with various systems In calculus, especially when developing programs, very often there is a need to translate small integers, then, generally speaking, it makes sense to memorize the first 16 numbers (from 0 to 15).

    But if you figure out how easy it is to mentally convert small integers from 0 to 15 from the decimal number system to binary, then you can simply calculate a significant part of the table in your head every time you need it. Do this operation many times, and at some point you yourself will not be able to understand whether you have already memorized the table or are still calculating.

    So, to convert a small positive integer from 0 to 15 from decimal to binary, the first thing you need to understand is that each position in binary number corresponds to a power of two. At the same time, powers of two for positions from 0 to 3 are very easy to remember - these are the numbers 1, 2, 4 and 8:

    And the number 10 is 2 plus 8:

    Well, the number 0 is a sin not to remember, since to get it you don’t need to add anything.

    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 binary system notation - 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. Table 1 shows the numbers in different systems Reckoning.

    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 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 - D. Therefore, our hexadecimal number- this 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 successively 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

    Received:

    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.