How to set up smartphones and PCs. Informational portal

Converting units from decimal to binary. Binary numbers, digits and binary number system

Instructions

Related Videos

The counting system we use every day has ten digits - from zero to nine. Therefore, it is called decimal. However, in technical calculations, especially those related to computers, other systems in particular binary and hexadecimal. Therefore, you need to be able to translate the numbers from one systems dead reckoning.

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 in binary the numbers, starting from the end, corresponds to a power of two. Two equals one, the first equals two, the second equals four, the third equals eight, and so on.

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

Inverse Problem - Decimal the numbers system. Suppose you have the number 57. To get its record, you must sequentially divide this number by 2 and write the remainder of the division. 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 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 division is zero. As a result, you got the binary number 111001.
Check the correctness of your answer: 111001 = 2 ^ 0 + 2 ^ 3 + 2 ^ 4 + 2 ^ 5 = 1 + 8 + 16 + 32 = 57.

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

To make a number from hexadecimal systems, you need to multiply each of its numbers by the corresponding power of sixteen and add the results. For example, decimal number # 11A is 10 * (16 ^ 0) + 1 * (16 ^ 1) + 1 * (16 ^ 2) = 10 + 16 + 256 = 282.

Reverse translation from decimal systems in hexadecimal is done by the same residual method as in binary. For example, take the number 10000. Sequentially dividing it by 16 and writing 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 if your answer is correct: # 2710 = 1 * (16 ^ 1) + 7 * (16 ^ 2) + 2 * (16 ^ 3) = 16 + 1792 + 8192 = 10000.

Transfer the numbers from hexadecimal systems to binary is much easier. The number 16 is 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 binary, add leading zeros.
For example, # 1F7E = (0001) (1111) (0111) (1110) = 1111101111110.
Check if the answer is correct: both the numbers in decimal notation equal to 8062.

To translate, you need to split 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 gives # 31A9 in hex. The correctness of the answer is confirmed by translation into decimal notation: both the numbers equal to 12713.

Tip 5: How to convert a number to binary

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

Instructions

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

Octal, hexadecimal and decimal systems are also widely used among positional systems. And if the second method is more applicable for the first two, then both are applicable for translation from.

Consider decimal to binary the system by dividing by 2. number 25 in

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 decimal, 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 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 2

n (degree)

Example.

2. To convert an octal number to decimal, 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 the eight:

Table 5. Powers of 8

n (degree)

Example. Convert the number to decimal notation.

3. To convert a hexadecimal number to decimal, it must be written as a polynomial consisting of the products of the digits of the number and the corresponding power of the number 16, and calculated according to the rules of decimal arithmetic:

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

Table 6. Powers of 16

n (degree)

Example. Convert the number to decimal notation.

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

Example. Convert the number to the binary system.

5. To convert a decimal number to the octal system, it must be sequentially divided by 8 until there is a remainder less than or equal to 7. The number in the octal system is written as a sequence of digits of the last division result and the remainder 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 is a remainder less than or equal to 15. The number in the hexadecimal system is written as a sequence of digits of the last division result and the remainder of the division in reverse order.

Example. Convert the number to hexadecimal notation.

To convert numbers from decimal s / s to any other, it is necessary to divide the decimal number by the base of the system into which they are transferred, while keeping the remainders of each division. The result is formed from right to left. Division continues until the result of division is less than the divisor.

The calculator converts numbers from one number system to any other. It can convert numbers from binary to decimal or from decimal to hexadecimal, showing the detailed progress of the solution. You can easily convert a number from ternary to fivefold, or even from sevenfold to sevenfold. The calculator can convert numbers from any number system to any other.

Online calculator: Convert numbers from one number system to any other online

Input data

Insert the number:


His number system
Binary
Ternary
Octal
Decimal
Hexadecimal
Binary decimal
Other

By triads
By notebooks

Which? (number)


Translate into
Binary
Trinity
Octal
Decimal
Hexadecimal
Binary decimal
Another

Which? (number)

Methods for translating numbers from one number system to another

Into the program Unified State Exam in Informatics includes several tasks related to the transfer of numbers from one system to another. Typically, this is a conversion between 8- and 16-ary systems and binary. These are the sections A1, AT 11... But there are also problems with other number systems, such as in the section B7.

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

Power table 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 these numbers, the rest are easy to get in your mind from those that you remember.

A table of binary numbers from 0 to 15 with hexadecimal notation:

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.

Arithmetic operations in the binary number system

When two numbers equal to 1 are added, 0 is obtained in this bit, and 1 is transferred to the most significant bit.

Integer translation

So, let's start by translating directly into the binary system. Let's take the same number 810 10. We need to expand this number into terms equal to powers of two.
  1. We are looking for the closest power of two to 810, not exceeding it. This is 2 9 = 512.
  2. Subtract 512 from 810 to get 298.
  3. Repeat steps 1 and 2 until 1 or 0 remains.
  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 ways, you can use either 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, cube 1000. That is, the degree of the base of the number system is 1 (one), and behind it there are as many zeros as the degree.

Method 1: Arrange 1 in those categories, which are the indicators of the terms. In our example, these are 9, 8, 5, 3 and 1. Zeros will be used in other places. So, we got the binary representation of the number 810 10 = 1100101010 2. Units stand at 9th, 8th, 5th, 3rd and 1st places, counting from right to left from zero.

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

810 =

Now let's put these steps together, as a fan folds: 1100101010.

That's all. Along the way, the problem "how many units are in the binary notation of the number 810?" Is also simply solved.

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

Now the example is simpler.

Let's translate the number 63 into the 5-ary number system. The closest power of 5 to 63 is 25 (square 5). The cube (125) will already be a lot. That is, 63 lies between square 5 and the cube. Then we 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 16-ary systems. Since their base is a power of two, the translation is done automatically, simply by replacing the digits 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.

Converting the number 547 8 into binary system.

547 8 = 101 100 111
5 4 7

Another one, for example 7D6A 16.

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

Let's translate the number 7368 into the hexadecimal system. First, write the numbers in threes, and then divide them into fours from the end: 736 8 = 111 011 110 = 1 1101 1110 = 1DE 16. Let's translate the number C25 16 into the 8-ary 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. He does not represent labor, the main thing is not to be mistaken in the calculations. We decompose the number into a polynomial with the degrees of the base and the coefficients at 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.

Translation of negative numbers

Here you need to take into account that the number will be represented in the's complement code. To translate a number into a complementary code, you need to know the final size of the number, that is, what we want to write it into - in a byte, in two bytes, in four. The most significant bit of a number means a sign. If there is 0, then the number is positive, if 1, then negative. On the left, the number is supplemented with a sign digit. Unsigned ( unsigned ) we do not consider numbers, they are always positive, and the most significant bit in them is used as informational.

To convert a negative number to binary's complement code, you need to convert a positive number to the binary system, then change zeros to ones and 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.

Convert 79 to binary, 79 = 1001111. Add zeros to the left to the size of a byte, 8 bits, we get 01001111. 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 question of the exam " how many units are in binary representation of the number -79?».

The answer is 4.

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

Fractional Numbers Translation

Fractional numbers are translated in the opposite way to the division of integers by the base, which we considered at the very beginning. That is, with the help of sequential multiplication by a new base, collecting whole parts. The whole 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 whole and fractional parts are translated separately, then glued together.

Converting the number 0.6752 to 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 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.

Javascript is disabled in your browser.
To make calculations, you need to enable ActiveX controls!

1. Ordinal account in various number systems.

In modern life, we use positional number systems, that is, systems in which the number denoted by a number depends on the position of the number in the number record. Therefore, in what follows we will only talk about them, omitting the term "positional".

In order to learn how to translate numbers from one system to another, let's understand how the sequential recording of numbers occurs using the decimal system as an example.

Since we have a decimal number system, we have 10 characters (digits) to construct numbers. We start the ordinal count: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. The numbers are over. We increase the digit capacity of the number and zero the least significant bit: 10. Then we increase the least significant bit again until all the digits run out: 11, 12, 13, 14, 15, 16, 17, 18, 19. Increase the most significant bit by 1 and zero the least significant one: 20. When we use all the digits for both digits (we get the number 99), we again increase the digit capacity of the number and reset the existing digits: 100. And so on.

Let's try to do the same in the 2nd, 3rd and 5th systems (we will enter the designation for the 2nd system, for the 3rd, etc.):

0 0 0 0
1 1 1 1
2 10 2 2
3 11 10 3
4 100 11 4
5 101 12 10
6 110 20 11
7 111 21 12
8 1000 22 13
9 1001 100 14
10 1010 101 20
11 1011 102 21
12 1100 110 22
13 1101 111 23
14 1110 112 24
15 1111 120 30

If the number system has a base of more than 10, then we will have to enter additional characters, it is customary to enter letters of the Latin alphabet. For example, for the 12-ary system, in addition to ten digits, we need two letters (s):

0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10
11
12 10
13 11
14 12
15 13

2. Conversion from decimal number system to any other.

To convert an integer positive decimal number to a number system with a different base, you need to divide this number by the base. Divide the resulting quotient by the base again, and further until the quotient is less than the base. As a result, write the last quotient and all the remainders starting from the last on one line.

Example 1. Converting decimal 46 to Binary number system.

Example 2. Converting Decimal 672 to Octal number system.

Example 3. Convert decimal number 934 to hexadecimal notation.

3. Conversion from any number system to decimal.

In order to learn how to convert numbers from any other system to decimal, let's analyze the usual notation of a decimal number.
For example, decimal number 325 is 5 units, 2 tens and 3 hundreds, i.e.

The situation is exactly the same in other number systems, only we will multiply not by 10, 100, etc., but by the degree of the base of the number system. For example, let's take the ternary number 1201. Let's number the digits from right to left starting from zero and represent our number as the sum of the products of a digit by a three in the degree of the digit of the number:

This is the decimal representation of our number, i.e.

Example 4. Converting the octal number 511 to decimal notation.

Example 5. Let's convert the hexadecimal number 1151 to the decimal number system.

4. Conversion from the binary system to the system with the base "power of two" (4, 8, 16, etc.).

To convert a binary number to a number with a base "power of two", it is necessary to divide the binary sequence into groups according to the number of digits equal to the power from right to left and replace each group with the corresponding digit of the new number system.

For example, Convert binary 1100001111010110 to octal. To do this, we divide it into groups of 3 characters, starting from the right (since), and then use the correspondence table and replace each group with a new digit:

We learned how to build a correspondence table in clause 1.

0 0
1 1
10 2
11 3
100 4
101 5
110 6
111 7

Those.

Example 6. Convert binary 1100001111010110 to hexadecimal number.

0 0
1 1
10 2
11 3
100 4
101 5
110 6
111 7
1000 8
1001 9
1010 A
1011 B
1100 C
1101 D
1110 E
1111 F

5. Transfer from the system with the base "power of two" (4, 8, 16, etc.) to binary.

This translation is similar to the previous one, performed in the opposite direction: we replace each digit with a group of digits in the binary system from the lookup table.

Example 7. Let's translate the hexadecimal number С3A6 into a binary number system.

To do this, replace each digit of the number with a group of 4 digits (since) from the correspondence table, adding, if necessary, the group with zeros at the beginning:



The result has already been received!

Number systems

There are positional and non-positional number systems. The Arabic numeral system that we use in everyday life is positional, but the Roman one is not. In positional numeration systems, the position of a number uniquely determines the magnitude of the number. Let's look at this using the decimal number 6372 as an example. Let's enumerate 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 this case, it is 10). The values ​​of the position of the given number are taken as the degrees.

Consider the real decimal number 1287.923. Let's number it starting from the zero position of the number from the decimal point to the left and to the 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 + D 0 s 0 + D -1 s -1 + D -2 s -2 + ... + D -k s -k

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

A few words about number systems. The 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 - from the set of numbers (0,1, 2,3,4,5,6,7), in the binary number system - from the set of digits (0,1), in the hexadecimal number system - from the set of numbers (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. numbers in different number systems are presented.

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, from the decimal number system, translate it into 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 notation (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 1011101.001 from octal number system (SS) to decimal SS. Solution:

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

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

Converting numbers from a decimal number system to another number system

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

The whole part of the number is transferred from the decimal SS to another number system - by sequentially dividing the whole part of the number by the base of the number system (for a binary SS - by 2, for an 8-ary SS - by 8, for a 16-ary - 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 seen from Fig. 1, the number 159 when divided by 2 gives the quotient 79 and the remainder 1. Further, the number 79 when divided by 2 gives the quotient 39 and the remainder 1, etc. As a result, having built a number from the remainder of the division (from right to left), we get the number in the 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 a whole remainder less than 8. As a result, building the number from the remainders of the division (from right to left), we get the number in octal SS: 1147 (see Fig. 2). Therefore, we can write:

615 10 =1147 8 .

Example 6 ... Convert the number 19673 from decimal to hexadecimal SS.

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

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

To convert correct decimal fractions (a real number with a zero integer part) to the base s, this number must be sequentially multiplied by s until a pure zero is obtained in the fractional part, or we get the required number of digits. If, during multiplication, a number with an integer part that is different from zero is obtained, then this integer part is not taken into account (they are sequentially added to the result).

Let's consider the above with examples.

Example 7 ... Convert the number 0.214 from decimal 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 multiplication results in a nonzero number with an integer part, then the integer part is written separately (to the left of the number), and the number is written with a zero integer part. If, when multiplying, a number with a zero integer part is obtained, then zero is written to the left of it. The multiplication process continues until a pure zero is obtained in the fractional part, or the required number of digits is obtained. Writing down 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 the 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, it turned out 0. Therefore, the following result was obtained:

0.125 10 =0.001 2 .

Example 9 ... Let's convert the number 0.214 from decimal 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 the 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 ... Converting Decimal to Decimal SS number 0.512.

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 ... Converting the number 159.125 from Decimal 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 ... Converting the number 19673.214 from decimal 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 get.

Top related articles