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.
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.