• How to convert from decimal to octal. Converting decimal numbers to octal number system

    Converting numbers from one number system to another is an important part of machine arithmetic. Let's consider the basic rules of translation.

    1. To convert a binary number to a decimal one, it is necessary to write it in the form of a polynomial consisting of the products of the digits of the number and the corresponding power of 2, and calculate it according to the rules of decimal arithmetic:

    When translating, it is convenient to use the table of powers of two:

    Table 4. Powers of number 2

    n (degree)

    Example.

    2. To convert an octal number to a decimal one, it is necessary to write it in the form of a polynomial consisting of the products of the digits of the number and the corresponding power of the number 8, and calculate it according to the rules of decimal arithmetic:

    When translating, it is convenient to use the table of powers of eight:

    Table 5. Powers of the number 8

    n (degree)

    Example. Convert the number to the decimal number system.

    3. To convert a hexadecimal number to a decimal one, it is necessary to write it in the form of a polynomial, consisting of the products of the digits of the number and the corresponding power of the number 16, and calculate it according to the rules of decimal arithmetic:

    When translating, it is convenient to use blitz of powers of number 16:

    Table 6. Powers of the number 16

    n (degree)

    Example. Convert the number to the decimal number system.

    4. To convert a decimal number to the binary system, it must be sequentially divided by 2 until a remainder less than or equal to 1 remains. A number in the binary system is written as a sequence of the last division result and the remainders from the division in reverse order.

    Example. Convert the number to the binary number system.

    5. To convert a decimal number to octal system it must be successively divided by 8 until there remains a remainder less than or equal to 7. A number in the octal system is written as a sequence of digits of the last division result and the remainders of the division in reverse order.

    Example. Convert the number to the octal number system.

    6. To convert a decimal number to the hexadecimal system, it must be sequentially divided by 16 until there remains a remainder less than or equal to 15. A number in the hexadecimal system is written as a sequence of digits of the last division result and the remainders from the division in reverse order.

    Example. Convert the number to hexadecimal number system.

    Laboratory work No. 1

    Topic: Number system. Translation of integers decimal numbers into binary, octal, hexadecimal number systems. (1 hour), SRSP (1 hour).

    Decimal number system

    The name "decimal" comes from the fact that this system is based on the base ten. This system uses ten digits to write numbers - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.

    The decimal system is positional because the meaning of a digit in a decimal number depends on its position, or location, in the number.

    The position allocated for the digit of a number is called digit.

    For example, the entry 526 means that the number consists of 5 hundreds, 2 tens and 6 ones. The number 6 is in the units place. The number 2 is in the tens place and the number 5 is in the hundreds place.

    Write this number as a sum:

    526=5*10 2 +2*10 1 +6*10 0

    in this entry the number 10 is the base of the number system. For each digit of a number, base 10 is raised to a power depending on the position of the digit and multiplied by that digit. The base power for units is zero, for tens it is one, for hundreds it is two, etc.

    Negative exponents are used to write decimal fractions. For example, the number 555.55 in expanded form is written as follows:

    555.55 10 = 5*10 2 + 5*10 1 + 5*10°+ 5*10- 1 +5*10- 2 .:

    Converting integer decimal numbers to the binary number system.

    When converting a decimal number to binary, you need to divide this number by 2. To convert an integer positive decimal number to the binary number system, you need to divide this number by 2. The resulting quotient is again divided by 2, etc. until the quotient is less than 2. As a result, write down the last quotient and all remainders, starting from the last, in one line.

    Example. Number 891 translate from decimal system into the binary number system.

    Solution:

    1:2=0, 1 (most significant digit of binary number)

    We write down in one line the last quotient and all remainders, starting from the last.

    Answer: 891 10 =1101111011 2

    Converting decimal fractions to binary number system

    Converting decimal fractions to the binary number system involves finding the whole parts when multiplying by 2.

    Example. Let's convert the decimal fraction 0.322 to the binary number system.

    To find the first digit after the decimal point of a binary fraction, you need to multiply the given number by 2 and select the integer part of the product.

    Solution:

    0,322 10 8,83 10

    0.322*2=0.644 0 8:2=4 remainder 0

    0.644*2=1.288 1 4:2=2 remainder 0

    0.288*2=0.576 0 2:2=1 remainder 0

    0.576*2=1.152 1 1:2=0 remainder 1

    0.3222 10 =0.0101 2 0.83*2=1.66 the integer part is 1

    0.66*2=1.32 the integer part is 1

    0.32*2=0.64 the integer part is 0

    0.64*2=1.28 the integer part is 1

    Answer: 8.83=1000.1101

    Converting decimal numbers to octal number system

    To convert a number from the decimal system to octal, the same technique is used as when converting to the binary system.

    The number being converted is divided by 8 according to the rules of the decimal system, storing the remainder, which, of course, does not exceed 7. If the resulting quotient is greater than 7, it is also divided by 8, keeping the remainder.

    Solution:

    (most significant digit of a binary number).

    Answer: 891 10 =1573 8

    For computer chips, only one thing is important. Either there is a signal (1) or there is no signal (0). But write programs in binary code- it's not an easy matter. On paper, you get very long combinations of zeros and ones. It's hard for a person.

    Using the familiar decimal system in computer documentation and programming is very inconvenient. Conversions from binary to decimal systems and vice versa are very labor-intensive processes.

    The origin of the octal system, as well as the decimal system, is associated with counting on fingers. But it is not the fingers that need to be counted, but the spaces between them. There are just eight of them.

    The solution to the problem was octal. At least at dawn computer equipment. When the processor capacity was small. The octal system made it easy to convert both binary numbers into octal and vice versa.

    The octal number system is a number system with a base of 8. It uses the numbers from 0 to 7 to represent numbers.

    Conversion

    To convert a number to binary, you need to replace each digit of the octal number with a triple from binary digits. It is only important to remember which binary combination corresponds to the digits of the number. There are very few of them. Only eight!
    In all number systems, except decimal, the digits are read one at a time. For example, in the octal system the number 610 is pronounced "six, one, zero."

    Video on the topic

    The components of electronic machines, which include computers, have only two distinguishable states: there is current and there is no current. They are designated "1" and "0" respectively. Since there are only two such states, many processes and operations in electronics can be described using binary numbers.

    Instructions

    Divide the decimal number by two until you get a remainder indivisible by two. At the step we get the remainder 1 (if the number was odd) or 0 (if the dividend is divisible by two without a remainder). All these balances must be taken into account. The last quotient obtained as a result of such step-by-step division will always be one.
    We write the last unit in the most significant digit of the desired binary, and write the remainders obtained in the process after this unit in reverse order. Here you need to be careful and not skip zeros.
    Thus, the number 235 in binary code will correspond to the number 11101011.

    Now let's convert the fractional part of the decimal number into the binary number system. To do this, we sequentially multiply the fractional part of the number by 2 and fix the integers of the resulting numbers. We add these integer parts to the number obtained in the previous step after the binary one in direct order.
    Then the decimal fraction 235.62 corresponds to the binary fraction 11101011.100111.

    Video on the topic

    Please note

    The binary fractional part of a number will be finite only if the fractional part of the original number is finite and ends in 5. The simplest case: 0.5 x 2 = 1, therefore 0.5 in the decimal system is 0.1 in the binary system.

    Sources:

    • Converting decimal numbers to binary in 2019

    Tip 4: How to convert binary numbers to decimal

    The binary or binary number system is used to display electronic information. Any number can be written in binary form. The binary system is used in all computers. Each entry in them is encoded according to certain rules using a set of two characters: 0 and 1. Translate binary number into its decimal representation, which is more convenient for the user, using the developed algorithm.

    Instructions

    Imagine the number as powers of 2. To do this, all eight digits are sequentially multiplied by the number 2 raised to . The degree must correspond to the digit category. The digit is counted from zero, starting from the least significant, rightmost symbol of the binary numbers. Write all eight composed works in .

    Tip 5: How to write a decimal number in the binary number system

    Decimal system dead reckoning– one of the most common in mathematical theory. However, with the advent information technology, the binary system is no less widespread, since it is the main way of representing information in computer memory.

    Instructions

    Conversion from decimal to binary is implemented for both integers and fractions. The conversion of an integer decimal number is carried out by sequentially dividing it by 2. In this case, the number of iterations (actions) increases until the quotient becomes zero, and the final binary number is written as the resulting residues from right to left.

    For example, the transformation of the number 19 looks like this: 19/2 = 18/2 + 1 = 9, the remainder is 1, we write 1;9/2 = 8/2 + 1 = 4, the remainder is 1, we write 1;4/ 2 = 2, there is no remainder, we write 0;2/2 = 1, there is no remainder, we write 0;1/2 = 0 + 1, the remainder is 1, we write 1. So, after the method of sequential division to the number 19 we got binary number 10011.

    Converting numbers from binary to octal and hexadecimal and vice versa

    Converting numbers between number systems whose bases are powers of 2 (q = 2 n) can be done using simpler algorithms. Such algorithms can be used to convert numbers between binary (q = 2 1), octal (q = 2 3) and hexadecimal (q = 2 4) number systems.

    Converting numbers from binary to octal. To write binary numbers, two digits are used, that is, in each digit of the number, 2 writing options are possible. We solve the exponential equation:

    2 = 2 i. Since 2 = 2 1, then i = 1 bit.

    Each bit of a binary number contains 1 bit of information.

    To write octal numbers, eight digits are used, that is, in each digit of the number, 8 writing options are possible. We solve the exponential equation:

    8 = 2 i. Since 8 = 2 3, then i = 3 bits.

    Each octal number contains 3 bits of information.

    So, to convert an integer binary number to octal, you need to break it down into groups of three digits, from right to left, and then convert each group to an octal digit. If the last, left, group contains less than three digits, then it must be supplemented on the left with zeros.

    Let's convert the binary number 101001 2 into octal in this way:

    101 001 2 => 1 × 2 2 + 0 × 2 1 + 1 × 2 0 0 × 2 2 + 0 × 2 1 + 1 × 2 0 => 51 8 .

    To simplify the translation, you can prepare in advance a table for converting binary triads (groups of 3 digits) into octal digits:

    Binary triads 000 001 010 011 100 101 110 111
    Octal digits 0 1 2 3 4 5 6 7

    To convert a fractional binary number (proper fraction) into octal, you need to divide it into triads from left to right and, if the last, right, group contains less than three digits, supplement it with zeros on the right. Next, you need to replace triads with octal numbers.

    For example, let’s transform the fractional binary number A 2 = 0.110101 2 into the octal number system:

    Binary triads 110 101
    Octal digits 6 5

    We get: A 8 = 0.65 8.

    Converting numbers from binary to hexadecimal. To write hexadecimal numbers, sixteen digits are used, that is, in each digit of the number, 16 writing options are possible. We solve the exponential equation:

    16 = 2 i. Since 16 = 2 4, then i = 4 bits.

    Each digit of a hexadecimal number contains 4 bits of information.

    Thus, to convert an integer binary number to hexadecimal, it must be divided into groups of four digits (tetrads), starting from the right, and, if the last left group contains less than four digits, pad it on the left with zeros. To convert a fractional binary number (proper fraction) into hexadecimal, you need to divide it into tetrads from left to right and, if the last right group contains less than four digits, then you need to pad it with zeros on the right.

    Then you need to convert each group into a hexadecimal digit, using a previously compiled table of correspondence between binary tetrads and hexadecimal digits.

    Let's convert the integer binary number A 2 = 101001 2 into hexadecimal:

    We get: A 16 = 0.D4 16.

    In order to convert any binary number into octal or hexadecimal number systems, it is necessary to carry out conversions using the algorithms discussed above separately for its integer and fractional parts.

    Converting numbers from octal and hexadecimal number systems to binary. To convert numbers from octal and hexadecimal number systems to binary, you need to convert the digits of the number into groups of binary digits. To convert from octal to binary, each digit of a number must be converted into a group of three binary digits (triad), and when converting a hexadecimal number, into a group of four digits (tetrad).

    For example, let's transform the fraction octal number A 8 = 0.47 8 in binary number system:

    As a result, we have: A 2 = 10101011 2

    3tasks

    1.16. Make a table of correspondence between binary tetrads and hexadecimal digits.

    1.17. Convert the following integers to octal and hexadecimal number systems: 1111 2, 1010101 2.

    1.18. Convert the following fractional numbers to octal and hexadecimal number systems: 0.01111 2, 0.10101011 2.

    1.19. Convert the following numbers to octal and hexadecimal number systems: 11.01 2, 110.101 2.

    1.20. Convert the following numbers to the binary number system: 46.27 8, EF,12 16.

    1.21. Compare numbers expressed in various systems notations: 1101 2 and D 16; 0.11111 2 and 0.22 8; 35.63 8 and 16, C 16.

    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 systems In notation, the position of a number uniquely determines the size 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 defines the number system (in in this case this 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, positioning 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 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 decimal SS to 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 proper decimal fractions ( 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 is 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.