How to convert 10 to 2 number system. Converting numbers from one number system to any other online
Lesson objectives:
- repeat the material studied on the topic of the number system;
- learn to convert a number from the decimal system to any other positional number system and vice versa;
- master the principles of converting numbers from one system to another;
- develop logical thinking.
Lesson progress
At the beginning of the lesson, a brief review and checking of homework.
In what form is numerical information presented in computer memory?
What are number systems used for?
What types of number systems do you know? Give your own examples.
How do positional systems differ from non-positional systems?
The goal of our lesson is to learn how to convert a number from the decimal system to any other positional number system and vice versa. But first we'll look at how you can
represent any non-negative integer:
In positional systems, the value of writing an integer is determined by the following rule: let a n a n-1 a n-2 …a 1 a 0 be the writing of the number A, and i are digits, then
where p is an integer greater than 1, which is called the base of the number system
In order for, for a given p, any non-negative integer could be written according to formula (1) and, moreover, in a unique way, the numerical values of the various digits must be different integers belonging to the segment from 0 to p-1.
1) Decimal system
numbers: 0,1,2,3,4,5,6,7,8,9
number 5735 = 5 10 3 +7 10 2 +3 10 1 +8 10 0
2) Ternary system
numbers: 0,1,2
number 201 3 = 2·3 2 +0·3 1 +1·3 0
Note: the subscript in a number indicates the base of the number system in which the number is written. For the decimal number system, the index need not be written.
Representation of negative and fractional numbers:
In all positional systems, the ‘–’ sign is used to write negative numbers, just like in the decimal system. A comma is used to separate the integer part of a number from the fractional part. The value of the entry a n a n-1 a n-2 …a 1 a 0 , a -1 a -2 …a m-2 a m-1 a m of the number A is determined by the formula, which is a generalization of formula (1):
75.6 = 7·10 1 +5·10 0 +6·10 –1
–2.314 5 = –(2 5 0 +3 5 –1 +1 5 –2 +4 5 –3)
Converting numbers from an arbitrary number system to decimal:
It should be understood that when translating a number from one number system to another, the quantitative value of the number does not change, but only the form of writing the number changes, just as when translating the name of a number, for example, from Russian into English.
Converting numbers from an arbitrary number system to decimal is performed by direct calculation using formula (1) for integers and formula (2) for fractions.
Converting numbers from the decimal number system to an arbitrary number system.
Converting a number from the decimal system to a system with base p means finding the coefficients in formula (2). Sometimes this is easy to do with a simple selection. For example, let's say you need to convert the number 23.5 to the octal system. It is easy to see that 23.5 = 16+7+0.5 = 2·8+7+4/8 = 2·8 1 +7·8 0 +4·8 –1 =27.48. It is clear that the answer is not always so obvious. In general, the method of converting the integer and fractional parts of a number separately is used.
To convert integers, the following algorithm is used (obtained based on formula (1)):
1. Find the quotient and remainder when dividing a number by p. The remainder will be the next digit ai (j=0,1,2...) of the number in the new number system.
2. If the quotient is equal to zero, then the translation of the number is completed, otherwise we apply point 1 to the quotient.
Note 1. The digits ai in the number notation are numbered from right to left.
Note 2. If p>10, then it is necessary to introduce notations for numbers with numerical values greater than or equal to 10.
Convert the number 165 to the septal number system.
165:7 = 23 (remainder 4) => a 0 = 4
23:7 = 3 (remainder 2) => a 1 = 2
3:7 = 0 (remainder 3) => a 2 = 3
Let's write down the result: a 2 a 1 a 0 , i.e. 3247.
Having checked using formula (1), we will make sure that the translation is correct:
3247=3·7 2 +2·7 1 +4·7 0 =3·49+2·7+4 = 147+14+4 = 165.
To convert fractional parts of numbers, an algorithm obtained based on formula (2) is used:
1. Multiply the fractional part of the number by p.
2. The integer part of the result will be the next digit am (m = –1, –2, –3 ...) of writing the number in the new number system. If the fractional part of the result is zero, then the translation of the number is completed, otherwise we apply step 1 to it.
Note 1. The digits a m in the number notation are arranged from left to right in increasing order of the absolute value of m.
Note 2. Usually the number of fractional digits in a new number entry is limited in advance. This allows you to perform an approximate translation with a given accuracy. In the case of infinite fractions, such a restriction ensures the finiteness of the algorithm.
Convert the number 0.625 to the binary number system.
0.625 2 = 1.25 (integer part 1) => a -1 =1
0.25 2 = 0.5 (integer part 0) => a- 2 = 0
0.5 2 = 1.00 (integer part 1) => a- 3 = 1
So 0.62510 = 0.1012
Having checked using formula (2), we will make sure that the translation is correct:
0.1012=1·2 -1 +0·2- 2 +1·2 -3 =1/2+1/8 = 0.5+0.125 = 0.625.
Convert the number 0.165 to the quaternary number system, limiting it to four quaternary digits.
0.165 4 = 0.66 (integer part 0) => a -1 =0
0.66 4 = 2.64 (integer part 2) => a -2 = 2
0.64 4 = 2.56 (integer part 2) => a -3 = 2
0.56 4 = 2.24 (integer part 2) => a -4 = 2
So 0.16510" 0.02224
Let's do a back translation to make sure that the absolute error does not exceed 4–4:
0.02224 = 0·4 -1 +2·4 -2 +2·4 -3 +2·4 -4 = 2/16+2/64+2/256 = 1/8+1/32+1/ 128 = 21/128 = 0.1640625
|0,1640625–0,165| = 0,00094 < 4–4 = 0,00390625
Converting numbers from one arbitrary system to another
In this case, you must first convert the number to the decimal system, and then from the decimal system to the required one.
A special method is used to convert numbers for systems with multiple bases.
Let p and q be the bases of two number systems. We will call these systems number systems with multiple bases if p = qn or q = pn, where n is a natural number. So, for example, number systems with bases 2 and 8 are multiple base number systems.
Let p = qn and you need to convert a number from a number system with base q to a number system with base p. Let's divide the integer and fractional parts of the number into groups of n sequentially written digits to the left and right of the decimal point. If the number of digits in the integer part of a number is not a multiple of n, then you need to add the corresponding number of zeros to the left. If the number of digits in the fractional part of a number is not a multiple of n, then zeros are added to the right. Each such group of digits of a number in the old number system will correspond to one digit of a number in the new number system.
Let's convert 1100001.111 2 to the quaternary number system.
By adding zeros and selecting pairs of numbers, we get 01100001.11102.
Now let’s translate each pair of digits separately, using the section Translating numbers from one arbitrary system to another.
So, 1100001.1112 = 01100001.11102 = 1201.324.
Let us now assume that we need to transfer from a system with a larger base q to a system with a smaller base p, i.e. q = pn. In this case, one digit of a number in the old number system corresponds to n digits of a number in the new number system.
Example: Let's check the previous translation of a number.
1201,324 = 1100001,11102=1100001,1112
In the hexadecimal system there are digits with numerical values 10,11,12, 13,14,15. To designate them, use the first six letters of the Latin alphabet A, B, C, D, E, F.
Here is a table of numbers from 0 to 16, written in number systems with bases 10, 2, 8 and 16.
Number in decimal system | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
In octal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 20 |
In binary | 0 | 1 | 10 | 11 | 100 | 101 | 110 | 111 | 1000 | 1001 | 1010 | 1011 | 1100 | 1101 | 1110 | 1111 | 10000 |
In hexadecimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | 10 |
To write hexadecimal digits, you can also use lowercase Latin letters a-f.
Example: Let's convert the number 110101001010101010100.11 2 into hexadecimal number system.
Let's use the multiplicity of the bases of the number systems (16=2 4). Let's group the numbers by four, adding the required number of zeros to the left and right
000110101001010101010100,1100 2
and, checking the table, we get: 1A9554,C 16
Conclusion:
Which number system is best to write numbers in is a matter of convenience and tradition. From a technical point of view, it is convenient to use the binary system in a computer, since it uses only two digits 0 and 1 to record a number, which can be represented by two easily distinguishable states “no signal” and “there is a signal.”
On the contrary, it is inconvenient for a person to deal with binary numbers due to the fact that they are longer than decimal numbers and there are many repeating digits in them. Therefore, if necessary, work with machine representations of numbers, use octal or hexadecimal number systems. The bases of these systems are integer powers of two, and therefore numbers are easily converted from these systems to binary and vice versa.
Write down the homework assignment:
a) Write down the date of birth of all members of your family in different number systems.
b) Convert numbers from binary to octal and hexadecimal, and then check the results by performing the reverse conversions:
a) 1001111110111.011 2;
To quickly convert numbers from the decimal number system to the binary system, you need to have a good knowledge of the numbers “2 to the power”. For example, 2 10 =1024, etc. This will allow you to solve some translation examples literally in seconds. One of these tasks is Problem A1 from the USE demo 2012. You can, of course, take a long and tedious time to divide a number by “2”. But it’s better to decide differently, saving valuable time on the exam.
The method is very simple. Its gist is this: If the number that needs to be converted from the decimal system is equal to the number "2 to the power", then this number in the binary system contains a number of zeros equal to the power. We add a “1” in front of these zeros.
- Let's convert the number 2 from the decimal system. 2=2 1 . Therefore, in the binary system, a number contains 1 zero. We put “1” in front and get 10 2.
- Let's convert 4 from the decimal system. 4=2 2 . Therefore, in the binary system, a number contains 2 zeros. We put “1” in front and get 100 2.
- Let's convert 8 from the decimal system. 8=2 3 . Therefore, in the binary system, a number contains 3 zeros. We put “1” in front and get 1000 2.
Similarly for other numbers "2 to the power".
If the number that needs to be converted is less than the number “2 to the power” by 1, then in the binary system this number consists only of units, the number of which is equal to the power.
- Let's convert 3 from the decimal system. 3=2 2 -1. Therefore, in the binary system, a number contains 2 ones. We get 11 2.
- Let's convert 7 from the decimal system. 7=2 3 -1. Therefore, in the binary system, a number contains 3 ones. We get 111 2.
In the figure, the squares indicate the binary representation of the number, and the decimal representation in pink on the left.
The translation is similar for other numbers “2 to the power-1”.
It is clear that the translation of numbers from 0 to 8 can be done quickly or by division, or simply know by heart their representation in the binary system. I gave these examples so that you understand the principle of this method and use it to translate more “impressive numbers”, for example, to translate the numbers 127,128, 255, 256, 511, 512, etc.
You can come across such problems when you need to convert a number that is not equal to the number “2 to the power”, but close to it. It may be greater or less than 2 to the power. The difference between the translated number and the number "2 to the power" should be small. For example, up to 3. The representation of numbers from 0 to 3 in the binary system just needs to be known without translation.
If the number is greater than , then solve like this:
First we convert the number “2 to the power” into the binary system. And then we add to it the difference between the number “2 to the power” and the number being translated.
For example, let's convert 19 from the decimal system. It is greater than the number "2 to the power" by 3.
16=2 4 . 16 10 =10000 2 .
3 10 =11 2 .
19 10 =10000 2 +11 2 =10011 2 .
If the number is less than the number "2 to the power", then it is more convenient to use the number "2 to the power-1". We solve it like this:
First we convert the number “2 to the power-1” into the binary system. And then we subtract from it the difference between the number “2 to the power of 1” and the number being translated.
For example, let's convert 29 from the decimal system. It is greater than the number “2 to the power-1” by 2. 29=31-2.
31 10 =11111 2 .
2 10 =10 2 .
29 10 =11111 2 -10 2 =11101 2
If the difference between the number being translated and the number "2 to the power" is more than three, then you can break the number into its components, convert each part into the binary system and add.
For example, convert the number 528 from the decimal system. 528=512+16. We translate 512 and 16 separately.
512=2 9
. 512 10 =1000000000
2 .
16=2 4
. 16 10 =10000
2 .
Now let's add it in a column:
To convert numbers from decimal s/s to any other, you need to divide the decimal number by the base of the system to which you are converting, while keeping the remainder from each division. The result is generated from right to left. The division continues until the result of the 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 decimal to hexadecimal, showing the detailed solution progress. You can easily convert a number from ternary to quinary or even from septenary to seventeenth. The calculator can convert numbers from any number system to any other.
Are there any difficulties or misunderstandings with converting numbers from binary to hexadecimal? Sign up with me for individual lessons in computer science and ICT. In our private lessons, my students and I analyze not only the theoretical part, but also solve a colossal number of different thematic exercises.
You need to know what a binary or binary number system is
Before thinking about how to convert a number from 2 to 16, you need to have a good understanding of what numbers are in the binary number system. Let me remind you that the alphabet of the binary number system consists of two valid elements - 0 And 1 . This means that absolutely any number written in binary will consist of a set of zeros and ones. Here are examples of numbers written in binary representation: 10010, 100, 111101010110, 1000001.
You need to know what the hexadecimal number system is
We figured out the binary system, remembered the basic points, now let's talk about the hexadecimal system. The alphabet of the hexadecimal number system consists of sixteen different characters: 10 Arabic numerals (from 0 to 9) and 6 first capital Latin letters (from “A” to “F”). This means that absolutely any number written in hexadecimal will consist of characters from the above alphabet. Here are examples of numbers written in hexadecimal notation:
810A | FCDF | 198303 | 100FFF0 |
Let's talk about the algorithm for converting a number from 2 to hexadecimal number system
We will definitely need to consider the Tetrad coding table. Without using this table, it will be quite difficult to quickly convert numbers from 2 to 16 system.
The purpose of the Tetrad encoding table is to uniquely match the symbols of the binary number system and the hexadecimal number system.
The Tetrad table has the following structure:
Tetrad table |
|||||||
0000 - 0 | 0001 - 1 | 0010 - 2 | 0011 - 3 | 0100 - 4 | 0101 - 5 | 0110 - 6 | 0111 - 7 |
1000 - 8 | 1001 - 9 | 1010 - A | 1011 - B | 1100 - C | 1101 - D | 1110 - E | 1111 - F |
Let's say we need to convert the number 101011111001010 2 to hexadecimal. First of all, it is necessary to divide the source binary code into groups of four bits, and, which is very important, the division must begin from right to left.
101 . 0111 . 1100 . 1010
After splitting, we received four groups: 101, 0111, 1100 and 1010. The leftmost segment, that is, segment 101, requires special attention. As you can see, its length is 3 digits, and it is necessary that its length be equal to four, therefore, we will supplement this segment leading zero:
101 -> 0 101.
Tell me, on what basis do we add some 0 to the left of the number? The thing is that adding insignificant zeros does not have any effect on the value of the original number. Consequently, we have every right to add not only one zero to the left of a binary number, but in principle any number of zeros and get a number of the required length.
At the final stage of the conversion, it is necessary to convert each of the resulting binary groups into the corresponding value according to the Tetrad coding table.
0101 -> 5 | 0111 -> 7 | 1100 -> C | 1010 -> A |
101011111001010 2 = 57CA 16
And now I suggest you familiarize yourself with the multimedia solution, which shows how it is converted from a binary state to a hexadecimal state:
Brief conclusions
In this short article we discussed the topic “ Number systems: how to convert from 2 to 16" If you have any questions or misunderstandings, please call and sign up for my individual lessons in computer science and programming. I will offer you to solve dozens of similar exercises and you will not have a single question left. In general, number systems are an extremely important topic that forms the foundation used throughout the course.
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 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 number systems.
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 to D. Therefore, our hexadecimal number 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.