Calculator for different number systems. positional number systems. Ways to represent numbers

There were some difficulties and misunderstandings with converting numbers from binary to hexadecimal system dead reckoning? 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 the numbers in binary system Reckoning 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 basic points, now let's talk about the hexadecimal system. The hexadecimal alphabet consists of sixteen different characters: 10 Arabic numerals (from 0 to 9) and 6 initial capitals 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:

810AFCDF198303 100FFF0

Let's talk about the algorithm for converting a number from 2 to hexadecimal number system

We will need in mandatory 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, you need the original binary code divided into groups of four categories, and, which is very important, the division must begin from right to left.

101 . 0111 . 1100 . 1010

After splitting, we got four groups: 101, 0111, 1100 and 1010. Special attention requires the leftmost segment, that is, segment 101. 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 with a leading insignificant 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. Therefore we have every right 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.

On final stage transformation, 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.

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 highest digit of the number in new system numbers with base d2, and the numbers 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: converting 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 a 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 system Reckoning

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.

Purpose of the service. The service is designed to convert numbers from one number system to another in online mode. To do this, select the base of the system from which you want to convert the number. You can enter both integers and numbers with commas.

Number

Conversion from 10 2 8 16 number system. Convert to 2 10 8 16 number system.
For fractional numbers, use 2 3 4 5 6 7 8 decimal places.

You can enter both whole numbers, for example 34, and fractional numbers, for example, 637.333. For fractional numbers, the translation accuracy after the decimal point is indicated.

The following are also used with this calculator:

Ways to represent numbers

Binary (binary) numbers - each digit means the value of one bit (0 or 1), the most significant bit is always written on the left, the letter “b” is placed after the number. For ease of perception, notebooks can be separated by spaces. For example, 1010 0101b.
Hexadecimal (hexadecimal) numbers - each tetrad is represented by one symbol 0...9, A, B, ..., F. This representation can be designated in different ways; here only the symbol “h” is used after the last hexadecimal digit. For example, A5h. In program texts, the same number can be designated as either 0xA5 or 0A5h, depending on the syntax of the programming language. A leading zero (0) is added to the left of the most significant hexadecimal digit represented by the letter to distinguish between numbers and symbolic names.
Decimal (decimal) numbers - each byte (word, double word) is represented by a regular number, and the decimal representation sign (the letter “d”) is usually omitted. The byte in the previous examples has a decimal value of 165. Unlike binary and hexadecimal notation, decimal is difficult to mentally determine the value of each bit, which is sometimes necessary.
Octal (octal) numbers - each triple of bits (division starts from the least significant) is written as a number 0–7, with an “o” at the end. The same number would be written as 245o. The octal system is inconvenient because the byte cannot be divided equally.

Algorithm for converting numbers from one number system to another

Converting whole decimal numbers to any other number system is carried out by dividing the number by the base of the new number system until the remainder remains a number less than the base of the new number system. The new number is written as division remainders, starting from the last one.
Converting a regular decimal fraction to another PSS is carried out by multiplying only the fractional part of the number by the base of the new number system until all zeros remain in the fractional part or until the specified translation accuracy is achieved. As a result of each multiplication operation, one digit of a new number is formed, starting with the highest one.
Improper fraction translation is carried out according to rules 1 and 2. The integer and fractional parts are written together, separated by a comma.

Example No. 1.



Conversion from 2 to 8 to 16 number system.
These systems are multiples of two, therefore the translation is carried out using a correspondence table (see below).

To convert a number from the binary number system to the octal (hexadecimal) number system, it is necessary to divide the binary number from the decimal point to the right and left into groups of three (four for hexadecimal) digits, supplementing the outer groups with zeros if necessary. Each group is replaced by the corresponding octal or hexadecimal digit.

Example No. 2. 1010111010.1011 = 1.010.111.010.101.1 = 1272.51 8
here 001=1; 010=2; 111=7; 010=2; 101=5; 001=1

When converting to the hexadecimal system, you must divide the number into parts of four digits, following the same rules.
Example No. 3. 1010111010,1011 = 10.1011.1010,1011 = 2B12,13 HEX
here 0010=2; 1011=B; 1010=12; 1011=13

Conversion of numbers from 2, 8 and 16 to the decimal system is carried out by breaking the number into individual ones and multiplying it by the base of the system (from which the number is translated) raised to the power corresponding to its serial number in the number being converted. In this case, the numbers are numbered to the left of the decimal point (the first number is numbered 0) in increasing order, and in right side with decreasing (i.e. with a negative sign). The results obtained are added up.

Example No. 4.
An example of conversion from binary to decimal number system.

1010010.101 2 = 1·2 6 +0·2 5 +1·2 4 +0·2 3 +0·2 2 +1·2 1 +0·2 0 + 1·2 -1 +0·2 - 2 +1 2 -3 =
= 64+0+16+0+0+2+0+0.5+0+0.125 = 82.625 10 An example of conversion from octal to decimal number system. 108.5 8 = 1*·8 2 +0·8 1 +8·8 0 + 5·8 -1 = 64+0+8+0.625 = 72.625 10 An example of conversion from hexadecimal to decimal number system. 108.5 16 = 1·16 2 +0·16 1 +8·16 0 + 5·16 -1 = 256+0+8+0.3125 = 264.3125 10

Once again we repeat the algorithm for converting numbers from one number system to another PSS

  1. From the decimal number system:
    • divide the number by the base of the number system being translated;
    • find the remainder when dividing an integer part of a number;
    • write down all remainders from division in reverse order;
  2. From the binary number system
    • To convert to the decimal number system, it is necessary to find the sum of the products of base 2 by the corresponding degree of digit;
    • To convert a number to octal, you need to break the number into triads.
      For example, 1000110 = 1,000 110 = 106 8
    • To convert a number from binary to hexadecimal, you need to divide the number into groups of 4 digits.
      For example, 1000110 = 100 0110 = 46 16
The system is called positional, for which the significance or weight of a digit depends on its location in the number. The relationship between the systems is expressed in a table.
Number system correspondence table:
Binary SSHex SS
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

Table for conversion to octal number system

Let's look at one of them the most important topics in computer science - . IN school curriculum it is revealed rather “modestly”, most likely due to the lack of hours allocated to it. Knowledge on this topic, especially on translation of number systems, are prerequisite for successfully passing the Unified State Exam and admission to universities at the relevant faculties. Below in detail concepts such as positional and non-positional number systems, examples of these number systems are given, rules are presented for converting whole decimal numbers, proper decimal fractions and mixed decimal numbers into any other number system, converting numbers from any number system into decimal, converting from octal and hexadecimal number systems into binary number system. On exams in large quantities There are problems on this topic. The ability to solve them is one of the requirements for applicants. Coming soon: For each topic of the section, in addition to detailed theoretical material, almost everyone will be represented possible options tasks For self-study. In addition, you will have the opportunity to download ready-made ones from a file hosting service completely free of charge. detailed solutions to these tasks, illustrating various ways getting the correct answer.

positional number systems.

Non-positional number systems- number systems in which the quantitative value of a digit does not depend on its location in the number.

Non-positional number systems include, for example, Roman, where instead of numbers there are Latin letters.

I 1 (one)
V 5 (five)
X 10 (ten)
L 50 (fifty)
C 100 (one hundred)
D 500 (five hundred)
M 1000 (thousand)

Here the letter V stands for 5 regardless of its location. However, it is worth mentioning that although the Roman number system is a classic example non-positional system notation is not completely non-positional, because The smaller number in front of the larger one is subtracted from it:

IL 49 (50-1=49)
VI 6 (5+1=6)
XXI 21 (10+10+1=21)
MI 1001 (1000+1=1001)

positional number systems.

Positional number systems- number systems in which the quantitative value of a digit depends on its location in the number.

For example, if we talk about the decimal number system, then in the number 700 the number 7 means “seven hundred”, but the same number in the number 71 means “seven tens”, and in the number 7020 - “seven thousand”.

Each positional number system has its own base. The basis is chosen natural number, greater than or equal to two. It is equal to the number of digits used in a given number system.

    For example:
  • Binary- positional number system with base 2.
  • Quaternary- positional number system with base 4.
  • Five-fold- positional number system with base 5.
  • Octal- positional number system with base 8.
  • Hexadecimal- positional number system with base 16.

To successfully solve problems on the topic “Number systems”, the student must know by heart the correspondence of binary, decimal, octal and hexadecimal numbers up to 16 10:

10 s/s 2 s/s 8 s/s 16 s/s
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
16 10000 20 10

It is useful to know how numbers are obtained in these number systems. You can guess that in octal, hexadecimal, ternary and others positional systems dead reckoning everything happens in the same way as the decimal system we are used to:

One is added to the number and a new number is obtained. If the units place becomes equal to the base of the number system, we increase the number of tens by 1, etc.

This “transition of one” is what frightens most students. In fact, everything is quite simple. The transition occurs if the units digit becomes equal to number base, we increase the number of tens by 1. Many, remembering the good old decimal system, are instantly confused about the digits in this transition, because decimal and, for example, binary tens are different things.

Hence, resourceful students develop “their own methods” (surprisingly... working) when filling out, for example, truth tables, the first columns (variable values) of which are, in fact, filled with binary numbers in ascending order.

For example, let's look at getting numbers in octal system: We add 1 to the first number (0), we get 1. Then we add 1 to 1, we get 2, etc. to 7. If we add one to 7, we get a number equal to the base of the number system, i.e. 8. Then you need to increase the tens digit by one (we get octal ten - 10). Next, obviously, are the numbers 11, 12, 13, 14, 15, 16, 17, 20, ..., 27, 30, ..., 77, 100, 101...

Rules for converting from one number system to another.

1 Converting integer decimal numbers to any other number system.

The number must be divided by new number system base. The first remainder of the division is the first minor digit of the new number. If the quotient of the division is less than or equal to the new base, then it (the quotient) must be divided again by the new base. The division must be continued until we get a quotient less than the new base. This is the highest digit of the new number (you need to remember that, for example, in the hexadecimal system, after 9 there are letters, i.e. if the remainder is 11, you need to write it as B).

Example ("division by corner"): Let's convert the number 173 10 to the octal number system.


Thus, 173 10 =255 8

2 Converting regular decimal fractions to any other number system.

The number must be multiplied by the new number system base. The digit that has become the integer part is the highest digit of the fractional part of the new number. to obtain the next digit, the fractional part of the resulting product must again be multiplied by a new base of the number system until the transition to the whole part occurs. We continue multiplication until the fractional part equals zero, or until we reach the accuracy specified in the problem (“... calculate with an accuracy of, for example, two decimal places”).

Example: Let's convert the number 0.65625 10 to the octal number system.

2.3. Converting numbers from one number system to another

2.3.1. Converting integers from one number system to another

It is possible to formulate an algorithm for converting integers from a radix system p into a system with a base q :

1. Express the base of the new number system using the numbers of the original number system and carry out all subsequent actions in original system Reckoning

2. Consistently divide the given number and the resulting integer quotients by the base of the new number system until we obtain a quotient that is smaller than the divisor.

3. The resulting remainders, which are digits of the number in the new number system, are brought into accordance with the alphabet of the new number system.

4. Compose a number in the new number system, writing it starting from the last remainder.

Example 2.12. Translate decimal number 173 10 in octal number system:

We get: 173 10 =255 8

Example 2.13. Convert the decimal number 173 10 to hexadecimal number system:

We get: 173 10 =AD 16.

Example 2.14. Convert the decimal number 11 10 to the binary number system. It is more convenient to depict the sequence of actions discussed above (translation algorithm) as follows:

We get: 11 10 =1011 2.

Example 2.15. Sometimes it is more convenient to write down the translation algorithm in table form. Let's convert the decimal number 363 10 to a binary number.

Divider

We get: 363 10 =101101011 2

2.3.2. Converting fractional numbers from one number system to another

It is possible to formulate an algorithm for converting a proper fraction with a base p into a fraction with a base q:

1. Express the base of the new number system with numbers from the original number system and carry out all subsequent actions in the original number system.

2. Consistently multiply the given numbers and the resulting fractional parts of the products by the base of the new system until the fractional part of the product becomes equal to zero or the required accuracy of number representation will be achieved.

3. The resulting integer parts of the products, which are digits of the number in the new number system, should be brought into conformity with the alphabet of the new number system.

4. Compose the fractional part of a number in the new number system, starting from the integer part of the first product.

Example 2.17. Convert the number 0.65625 10 to the octal number system.

We get: 0.65625 10 =0.52 8

Example 2.17. Convert the number 0.65625 10 to hexadecimal number system.

x 16

We get: 0.65625 10 =0.A8 1

Example 2.18. Convert the decimal fraction 0.5625 10 to the binary number system.

x 2

x 2

x 2

x 2

We get: 0.5625 10 =0.1001 2

Example 2.19. Convert to binary number system decimal 0.7 10 .

Obviously, this process can continue indefinitely, giving more and more new signs in the image of the binary equivalent of the number 0.7 10. So, in four steps we get the number 0.1011 2, and in seven steps the number 0.1011001 2, which is a more accurate representation of the number 0.7 10 in binary number system, and etc. Such an endless process is terminated at a certain step, when it is considered that the required accuracy of number representation has been obtained.

2.3.3. Translation of arbitrary numbers

Translation of arbitrary numbers, i.e. numbers containing integer and fractional parts are carried out in two stages. Separately translated whole part, separately - fractional. In the final recording of the resulting number, the integer part is separated from the fractional part by a comma (dot).

Example 2.20. Convert the number 17.25 10 to the binary number system.

We get: 17.25 10 =1001.01 2

Example 2.21. Convert the number 124.25 10 to octal system.

We get: 124.25 10 =174.2 8

2.3.4. Converting numbers from base 2 to base 2 n and vice versa

Translation of integers. If the base of the q-ary number system is a power of 2, then the conversion of numbers from the q-ary number system to the 2-ary number system and back can be carried out using more simple rules. In order to write an integer binary number in the number system with base q=2 n, you need:

1. Divide the binary number from right to left into groups of n digits each.

2. If the last left group has less than n digits, then it must be supplemented on the left with zeros to the required number of digits.

Example 2.22. The number 101100001000110010 2 will be converted to the octal number system.

We divide the number from right to left into triads and under each of them write the corresponding octal digit:

We get the octal representation of the original number: 541062 8 .

Example 2.23. The number 1000000000111110000111 2 will be converted to the hexadecimal number system.

We divide the number from right to left into tetrads and under each of them write the corresponding hexadecimal digit:

We get the hexadecimal representation of the original number: 200F87 16.

Converting fractional numbers. In order to write a fractional binary number in a number system with base q=2 n, you need:

1. Divide the binary number from left to right into groups of n digits each.

2. If the last right group has less than n digits, then it must be supplemented on the right with zeros to the required number of digits.

3. Consider each group as an n-bit binary number and write it with the corresponding digit in the number system with the base q=2 n.

Example 2.24. The number 0.10110001 2 will be converted to the octal number system.

We divide the number from left to right into triads and under each of them we write the corresponding octal digit:

We get the octal representation of the original number: 0.542 8 .

Example 2.25. The number 0.100000000011 2 will be converted to the hexadecimal number system. We divide the number from left to right into tetrads and under each of them write the corresponding hexadecimal digit:

We get the hexadecimal representation of the original number: 0.803 16

Translation of arbitrary numbers. In order to write an arbitrary binary number in the number system with the base q=2 n, you need:

1. Divide the integer part of a given binary number from right to left, and the fractional part from left to right into groups of n digits each.

2. If the last left and/or right groups have less than n digits, then they must be supplemented on the left and/or right with zeros to the required number of digits;

3. Consider each group as an n-bit binary number and write it with the corresponding digit in the number system with the base q = 2 n

Example 2.26. Let's convert the number 111100101.0111 2 to the octal number system.

We divide the integer and fractional parts of the number into triads and under each of them write the corresponding octal digit:

We get the octal representation of the original number: 745.34 8 .

Example 2.27. The number 11101001000,11010010 2 will be converted to the hexadecimal number system.

We divide the integer and fractional parts of the number into notebooks and under each of them write the corresponding hexadecimal digit:

We get the hexadecimal representation of the original number: 748,D2 16.

Converting numbers from number systems with base q=2n to binary. In order to convert an arbitrary number written in the number system with the base q=2 n into the binary number system, you need to replace each digit of this number with its n-digit equivalent in the binary number system.

Example 2.28.Let's convert the hexadecimal number 4AC35 16 to the binary number system.

According to the algorithm:

We get: 1001010110000110101 2 .

Tasks for independent completion (Answers)

2.38. Fill out the table, in each row of which the same integer must be written in various systems Reckoning

Binary

Octal

Decimal

Hexadecimal

2.39. Fill out the table with the same thing in each row a fractional number must be written in different number systems.

Binary

Octal

Decimal

Hexadecimal

2.40. Fill out the table, in each row of which the same arbitrary number (the number can contain both an integer and a fractional part) must be written in different number systems.

Binary

Octal

Decimal

Hexadecimal

59.B