IN Everyday life We are accustomed to using the decimal number system, familiar to us since school. However, besides it, there are many other systems. How to write numbers not in decimal, but, for example, in ?

How to convert any number from the decimal system to binary

Need to translate decimal number in binary form it looks scary only at first glance. In fact, it is quite simple - you don’t even have to look for online services to complete the transaction.

  • For example, let's take the number 156, written in the decimal form we are familiar with, and try to convert it into binary form.
  • The algorithm will look like this - the initial number will need to be divided by two, then again by 2, and again by 2 until the answer remains one.
  • When performing division, it is not the integers that matter for conversion to binary, but the remainders. If, when dividing, the answer turns out to be even number, then the remainder is written as the number 0, if odd, then as the number 1.
  • In practice, you can easily verify that the initial binary series of remainders for the number 156 will look like this - 00111001. In order to turn it into a full-fledged binary code, this series will need to be written in reverse order- that is, 10011100.

The binary number 10011100, obtained as a result of a simple operation, will be the binary expression of the number 156.

Another example, but in the picture

Converting binary number to decimal system

The reverse conversion - from binary to decimal - may seem a little more complicated. But if you use a simple doubling method, then you can handle this task in a couple of minutes. For example, let's take the same number, 156, but in binary form - 10011100.

  • The doubling method is based on the fact that at each step of the calculation, the so-called previous total is taken and the next digit is added to it.
  • Since at the first step the previous total does not yet exist, here we always take 0, double it and add the first digit of the expression to it. In our example it will be 0 * 2 + 1 = 1.
  • At the second step, we already have the previous total - it is equal to 1. This number needs to be doubled, and then the next one in order should be added to it, that is - 1 * 2 + 0 = 2.
  • In the third, fourth and subsequent steps, the previous totals are still taken and added to the subsequent number in the expression.

When only the last digit remains in the binary notation, and there is nothing more to add, the operation is completed. With a simple check, you can make sure that the answer contains the desired decimal number 156.

Note 1

If you want to convert a number from one number system to another, then it is more convenient to first convert it to the decimal number system, and only then convert it from the decimal number system to any other number system.

Rules for converting numbers from any number system to decimal

In computing technology that uses machine arithmetic, the conversion of numbers from one number system to another plays an important role. Below we give the basic rules for such transformations (translations).

    When converting a binary number to a decimal, you need to represent the binary number as a polynomial, each element of which is represented as the product of a digit of the number and the corresponding power of the base number, in this case $2$, and then you need to calculate the polynomial using the rules of decimal arithmetic:

    $X_2=A_n \cdot 2^(n-1) + A_(n-1) \cdot 2^(n-2) + A_(n-2) \cdot 2^(n-3) + ... + A_2 \cdot 2^1 + A_1 \cdot 2^0$

Figure 1. Table 1

Example 1

Convert the number $11110101_2$ to the decimal number system.

Solution. Using the given table of $1$ powers of the base $2$, we represent the number as a polynomial:

$11110101_2 = 1 \cdot 27 + 1 \cdot 26 + 1 \cdot 25 + 1 \cdot 24 + 0 \cdot 23 + 1 \cdot 22 + 0 \cdot 21 + 1 \cdot 20 = 128 + 64 + 32 + 16 + 0 + 4 + 0 + 1 = 245_(10)$

    To convert a number from the octal number system to the decimal number system, you need to represent it as a polynomial, each element of which is represented as the product of a digit of the number and the corresponding power of the base number, in this case $8$, and then you need to calculate the polynomial according to the rules of decimal arithmetic:

    $X_8 = A_n \cdot 8^(n-1) + A_(n-1) \cdot 8^(n-2) + A_(n-2) \cdot 8^(n-3) + ... + A_2 \cdot 8^1 + A_1 \cdot 8^0$

Figure 2. Table 2

Example 2

Convert the number $75013_8$ to the decimal number system.

Solution. Using the given table of $2$ powers of the base $8$, we represent the number as a polynomial:

$75013_8 = 7\cdot 8^4 + 5 \cdot 8^3 + 0 \cdot 8^2 + 1 \cdot 8^1 + 3 \cdot 8^0 = 31243_(10)$

    To convert a number from hexadecimal to decimal, you need to represent it as a polynomial, each element of which is represented as the product of a digit of the number and the corresponding power of the base number, in this case $16$, and then you need to calculate the polynomial according to the rules of decimal arithmetic:

    $X_(16) = A_n \cdot 16^(n-1) + A_(n-1) \cdot 16^(n-2) + A_(n-2) \cdot 16^(n-3) + . .. + A_2 \cdot 16^1 + A_1 \cdot 16^0$

Figure 3. Table 3

Example 3

Convert the number $FFA2_(16)$ to the decimal number system.

Solution. Using the given table of $3$ powers of the base $8$, we represent the number as a polynomial:

$FFA2_(16) = 15 \cdot 16^3 + 15 \cdot 16^2 + 10 \cdot 16^1 + 2 \cdot 16^0 =61440 + 3840 + 160 + 2 = 65442_(10)$

Rules for converting numbers from the decimal number system to another

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

Example 4

Convert the number $22_(10)$ to the binary number system.

Solution:

Figure 4.

$22_{10} = 10110_2$

  • To convert a number from the decimal number system to octal, it must be sequentially divided by $8$ until there is a remainder less than or equal to $7$. A number in the octal number system is represented as a sequence of digits of the last division result and the remainders from the division in reverse order.

Example 5

Convert the number $571_(10)$ to the octal number system.

Solution:

Figure 5.

$571_{10} = 1073_8$

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

Example 6

Convert the number $7467_(10)$ to hexadecimal number system.

Solution:

Figure 6.

$7467_(10) = 1D2B_(16)$

    In order to convert a proper fraction from a decimal number system to a non-decimal number system, it is necessary to sequentially multiply the fractional part of the number being converted by the base of the system to which it needs to be converted. Fraction in new system will be presented in the form of entire parts of works, starting with the first.

    For example: $0.3125_((10))$ in octal number system will look like $0.24_((8))$.

    In this case, you may encounter a problem when the final decimal may correspond to an infinite (periodic) fraction in the non-decimal number system. In this case, the number of digits in the fraction represented in the new system will depend on the required accuracy. It should also be noted that integers remain integers, and proper fractions remain fractions in any number system.

Rules for converting numbers from a binary number system to another

  • To convert a number from the binary number system to octal, it must be divided into triads (triples of digits), starting with the least significant digit, if necessary, adding zeros to the leading triad, then replace each triad with the corresponding octal digit according to Table 4.

Figure 7. Table 4

Example 7

Convert the number $1001011_2$ to the octal number system.

Solution. Using Table 4, we convert the number from the binary number system to octal:

$001 001 011_2 = 113_8$

  • To convert a number from the binary number system to hexadecimal, it should be divided into tetrads (four digits), starting with the least significant digit, if necessary, adding zeros to the most significant tetrad, then replace each tetrad with the corresponding octal digit according to Table 4.

Methods for converting numbers from one number system to another.

Converting numbers from one positional number system to another: converting integers.

To convert an integer from one number system with base d1 to another with base d2, you must sequentially divide this number and the resulting quotients by base d2 of the new system until you get a quotient less than base d2. The last quotient is the most significant digit of a number in the new number system with base d2, and the digits following it are remainders from division, written in the reverse order of their receipt. Perform arithmetic operations in the number system in which the number being translated is written.

Example 1. Convert the number 11(10) to the binary number system.

Answer: 11(10)=1011(2).

Example 2. Convert the number 122(10) to the octal number system.


Answer: 122(10)=172(8).

Example 3. Convert the number 500(10) to hexadecimal number system.


Answer: 500(10)=1F4(16).

Converting numbers from one positional number system to another: translation proper fractions.

To convert a proper fraction from a number system with base d1 to a system with base d2, it is necessary to sequentially multiply the original fraction and the fractional parts of the resulting products by the base of the new number system d2. The correct fraction of a number in the new number system with base d2 is formed in the form of integer parts of the resulting products, starting from the first.
If the translation results in a fraction in the form of an infinite or divergent series, the process can be completed when the required accuracy is achieved.

When translating mixed numbers, it is necessary to separately translate the integer and fractional parts into the new system according to the rules for translating integers and proper fractions, and then combine both results into one mixed number in the new number system.

Example 1. Convert the number 0.625(10) to the binary number system.


Answer: 0.625(10)=0.101(2).

Example 2. Convert the number 0.6(10) to the octal number system.


Answer: 0.6(10)=0.463(8).

Example 2. Convert the number 0.7(10) to hexadecimal number system.


Answer: 0.7(10)=0.B333(16).

Convert binary, octal and hexadecimal numbers to decimal number system.

To convert a number from the P-ary system to a decimal one, you must use the following expansion formula:
аnan-1…а1а0=аnPn+ аn-1Pn-1+…+ а1P+a0 .

Example 1. Convert the number 101.11(2) to the decimal number system.

Answer: 101.11(2)= 5.75(10) .

Example 2. Convert the number 57.24(8) to the decimal number system.

Answer: 57.24(8) = 47.3125(10) .

Example 3. Convert the number 7A,84(16) to the decimal number system.

Answer: 7A.84(16)= 122.515625(10) .


Converting octal and hexadecimal numbers to the binary number system and vice versa.

To convert a number from the octal number system to binary, each digit of this number must be written as a three-digit binary number (triad).

Example: write the number 16.24(8) in the binary number system.


Answer: 16.24(8)= 1110.0101(2) .

To convert a binary number back into the octal number system, you need to divide the original number into triads to the left and right of the decimal point and represent each group with a digit in the octal number system. Extreme incomplete triads are supplemented with zeros.

Example: write the number 1110.0101(2) in the octal number system.


Answer: 1110.0101(2)= 16.24(8) .

To convert a number from the hexadecimal number system to the binary system, you need to write each digit of this number as a four-digit binary number (tetrad).

Example: write the number 7A,7E(16) in the binary number system.


Answer: 7A,7E(16)= 1111010.0111111(2) .

Note: leading zeros on the left for integers and on the right for fractions are not written.

To convert a binary number back into the hexadecimal number system, you need to divide the original number into tetrads to the left and right of the decimal point and represent each group with a digit in the hexadecimal number system. Extreme incomplete triads are supplemented with zeros.

Example: write the number 1111010.0111111(2) in hexadecimal number system.

We encounter the binary number system when studying computer disciplines. After all, it is on the basis of this system that the processor and some types of encryption are built. There are special algorithms for writing a decimal number in the binary system and vice versa. If you know the principle of building a system, it will not be difficult to operate in it.

The principle of constructing a system of zeros and ones

The binary number system is built using two digits: zero and one. Why these particular numbers? This is due to the principle of constructing the signals that are used in the processor. At its lowest level, the signal takes only two values: false and true. Therefore, it was customary to denote the absence of a signal, “false,” by zero, and its presence, “true,” by one. This combination is easy to implement technically. Numbers in the binary system are formed in the same way as in the decimal system. When a digit reaches its upper limit, it is reset to zero and a new digit is added. This principle is used to move through a ten in the decimal system. Thus, numbers are made up of combinations of zeros and ones, and this combination is called the “binary number system”.

Recording a number in the system

In decimal

In binary

In decimal

In binary

How to write a binary number as a decimal number?

There are online services that convert numbers into binary and vice versa, but it’s better to be able to do it yourself. When translated, the binary system is denoted by the subscript 2, for example, 101 2. Each number in any system can be represented as a sum of numbers, for example: 1428 = 1000 + 400 + 20 + 8 - in the decimal system. The number is also represented in binary. Let's take an arbitrary number 101 and consider it. It has 3 digits, so we arrange the number in order in this way: 101 2 =1×2 2 +0×2 1 +1×2 0 =4+1=5 10, where the index 10 denotes the decimal system.

How to write a prime number in binary?

It is very easy to convert to the binary number system by dividing the number by two. It is necessary to divide until it is possible to complete it completely. For example, take the number 871. We begin to divide, making sure to write down the remainder:

871:2=435 (remainder 1)

435:2=217 (remainder 1)

217:2=108 (remainder 1)

The answer is written according to the resulting remainders in the direction from end to beginning: 871 10 =101100111 2. You can check the correctness of the calculations using the reverse translation described earlier.

Why do you need to know translation rules?

The binary number system is used in most disciplines related to microprocessor electronics, coding, data transmission and encryption, and in various areas of programming. Knowledge of the basics of translation from any system to binary will help the programmer develop various microcircuits and control the operation of the processor and other similar systems programmatically. The binary number system is also necessary for implementing methods for transmitting data packets over encrypted channels and creating client-server software projects based on them. In a school computer science course, the basics of converting to the binary system and vice versa are the basic material for studying programming in the future and creating simple programs.

Instructions

Video on the topic

In the counting system that we use every day, there are ten digits - from zero to nine. That's why it's called decimal. However, in technical calculations, especially those related to computers, other systems, specifically binary and hexadecimal. Therefore you need to be able to translate numbers from one systems counting to another.

You will need

  • - a piece of paper;
  • - pencil or pen;
  • - calculator.

Instructions

The binary system is the simplest. It has only two digits - zero and one. Each digit of binary numbers, starting from the end, corresponds to a power of two. Two in equals one, in the first - two, in the second - four, in the third - eight, and so on.

Suppose you are given the binary number 1010110. The units in it are in second, third, fifth and seventh places. Therefore, in the decimal system this number is 2^1 + 2^2 + 2^4 + 2^6 = 2 + 4 + 16 + 64 = 86.

Inverse problem - decimal numbers system. Let's say you have the number 57. To get it, you must sequentially divide the number by 2 and write the remainder. The binary number will be built from end to beginning.
The first step will give you the last digit: 57/2 = 28 (remainder 1).
Then you get the second one from the end: 28/2 = 14 (remainder 0).
Further steps: 14/2 = 7 (remainder 0);
7/2 = 3 (remainder 1);
3/2 = 1 (remainder 1);
1/2 = 0 (remainder 1).
This is the last step because the result of division is zero. As a result, you got the binary number 111001.
Check your answer: 111001 = 2^0 + 2^3 + 2^4 + 2^5 = 1 + 8 + 16 + 32 = 57.

The second, used in computer matters, is hexadecimal. It has not ten, but sixteen digits. To avoid new conventions, the first ten digits of hexadecimal systems are designated by ordinary numbers, and the remaining six - by Latin letters: A, B, C, D, E, F. They correspond to decimal notation numbers m from 10 to 15. To avoid confusion, the number written in hexadecimal is preceded by the # sign or the symbols 0x.

Reverse conversion from decimal systems to hexadecimal is done using the same method of remainders as to binary. For example, take the number 10000. Consistently dividing it by 16 and writing down the remainders, you get:
10000/16 = 625 (remainder 0).
625/16 = 39 (remainder 1).
39/16 = 2 (remainder 7).
2/16 = 0 (remainder 2).
The result of the calculation will be the hexadecimal number #2710.
Check your answer: #2710 = 1*(16^1) + 7*(16^2) + 2*(16^3) = 16 + 1792 + 8192 = 10000.

Transfer numbers from hexadecimal systems It's much easier to convert to binary. The number 16 is a two: 16 = 2^4. Therefore, each hexadecimal digit can be written as a four-digit binary number. If you have less than four digits in a binary number, add leading zeros.
For example, #1F7E = (0001)(1111)(0111)(1110) = 1111101111110.
Check the answer: both numbers in decimal notation they are equal to 8062.

To translate, you need to break the binary number into groups of four digits, starting from the end, and replace each such group with a hexadecimal digit.
For example, 11000110101001 becomes (0011)(0001)(1010)(1001), which in hexadecimal notation equals #31A9. The correctness of the answer is confirmed by conversion to decimal notation: both numbers are equal to 12713.

Tip 5: How to convert a number to binary

Due to its limited use of symbols, the binary system is most convenient for use in computers and other digital devices. There are only two symbols: 1 and 0, so this system used in the operation of registers.

Instructions

Binary is positional, i.e. The position of each digit in a number corresponds to a certain digit, which is equal to two to the appropriate power. The degree starts at zero and increases as you move from right to left. For example, number 101 is equal to 1*2^0 + 0*2^1 + 1*2^2 = 5.

Consider a decimal number to binary system by sequential division by 2. To convert a decimal number 25 into the code, you need to divide it by 2 until 0 remains. The remainders obtained at each division step are written in a line from right to left, after writing the digit of the last remainder this will be the final