B in 16 number system. Hex code

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:

810AFCDF198303 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 digits, 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.

Converting numbers from the 8th number system to the 16th. 568?2E16.

Picture 19 from the presentation “Translation of number systems” for mathematics lessons on the topic “Types of number systems”

Dimensions: 960 x 720 pixels, format: jpg. To download a free picture for a math lesson, right-click on the image and click “Save image as...”. To display pictures in the lesson, you can also download for free the entire presentation “Translation of number systems.ppsx” with all the pictures in a zip archive. The archive size is 138 KB.

Download presentation

Types of number systems

"Binary system" - 1, 2, 4, 8, 16, 32, 64, 128,... Converting integer decimal numbers to binary code. Any decimal number can be represented as the sum of the terms of a series: Wilhelm Gottfried Leibniz (1646-1716). Let's convert the number 121 to the binary number system. Binary number system. Method 1 – difference method.

“Examples of number systems” - Roman number system. CCC. Discharges. 11. 1999 =. Numbers: 123, 45678, 1010011, CXL Numbers: 0, 1, 2, … 4 3 2 1 0. M M. = 1644. – 10. 5. I, V, X, L, … IX. 6. = 1·24 + 0·23 + 0·22 + 1·21 + 1·20 = 16 + 2 + 1 = 19. Topic 2. Binary number system.

“Positional and non-positional number systems” - All number representation systems are divided into positional and non-positional. Any positional number system is characterized by a base. Therefore, positional number systems are predominantly used. An expanded form of writing numbers in the positional number system. Number systems. In practice, the abbreviated notation of numbers is used: A= anan-1 ... a1a0a-1... a-m.

“Different number systems” - Summing up the lesson, homework. Positional number systems. Alphabetic number systems. Lesson is over, goodbye! Practical task: Write in Roman numerals: 29, 57, 128, 1024. Learn theoretical material. The SS alphabet is the digits used to write numbers. Get the correct equalities (you are allowed to move 1 stick): VII – V = XI; IX – V = VI.

“Writing numbers in number systems” - The contents of any file are presented in this form. The Roman system is fundamentally not much different from the Egyptian one. Decimal system. Number systems. Alphabetic systems were more advanced non-positional number systems. Binary system. The symbols used to represent a number are numbers from 0 to 9.

“Number systems lesson” - How does a computer work? Lesson 7. Binary arithmetic (16 ss). Lesson 1. 2cc: 0, 1 8cc: 0, 1, 2, 3, 4, 5, 6, 7 10cc: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 16cc: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,A , B, C, D, E, F. What number system does the computer use? The clock operates in duodecimal SS. 111, 555. The computer operates in the binary number system.

There are a total of 13 presentations in the topic

Lesson type: lesson – consolidation of what has been learned. (summarizing)

Type: combined lesson.

Goal: To generalize and apply knowledge about the methods and methods of number translations to solve the problem. Development of cognitive interest and creative activity of students.

Lesson objectives:

Educational: deepening, generalizing and systematizing techniques for converting numbers from one number system to another.
Educational: development of cognitive interest, logical thinking.
Developmental: development of algorithmic thinking, memory, attentiveness.

During the classes:

  1. Organizational moment (3 min).
  2. Checking homework:
  3. a) Theory: Calculator (3 min);
    b) Practice: checking the work history at the PC (7 min).

  4. The “8-2-16” principle
  5. a) theory: the essence of the principle, examples (10 min);
    b) practice: complete a practical task (using cards) (15 min).

  6. Recording homework (2 min).
  7. Summarizing.

1. Organizational moment.
2. Checking homework:

a) Go through the rows and look (superficially - whether there is or not) the recordings of the solutions to the exercises. Invite students to check their homework on their own using a PC. To do this, we use the standard Windows OS application – Calculator.

Write on the board and in your notebook:

Launch: Start – Programs – Accessories – Calculator

Team: Type – Engineering.

With this program you can convert numbers written in binary, octal, decimal and hexadecimal coordinate systems. Have designations:

Hex (Hexadecimal) - hexadecimal

Dec (Decimal) - decimal

Oct (Octal) - octal

Bin (Binary) – binary.

Picture 1

Number translation algorithm:

For example, translate the number 19F 16 =X 10.

    1. Set the switch to the Hex position (by clicking on it with the left mouse button).
    2. Enter the number using the mouse or keyboard (Latin letters).
    3. Set the switch to the Dec position - we get the answer.
    4. Check the correctness in your notebook and put +.

b) Students sit down at the computers and perform a self-test.

  1. We have learned how to convert numbers from one system to another (in writing or using the Calculator program), and now let's look at transfer methods that do not require any calculations from us. Let's call it the “8-2-16 Principle”.

a) I distribute cards with tables on the table:

Table for converting numbers from 8 s.s. at 2 s.s. and vice versa through TRIADS.
8 s.s.
000 100
001 5 101
010 6 110
3 011 7 111

For example:

611 8 =110 001 001 2
101 111 111 2 =577 8 .

Table for converting numbers from 16 s.s. at 2 s.s. and vice versa through TETRADS.

16 p.m. 2 c.c. 16 p.m. 2 c.c.
0 0000 8 1000
1 0001 9 1001
2 0010 A 1010
3 0011 B 1011
4 0100 C 1100
5 0101 D 1101
6 0110 E 1110
7 0111 F 1111

For example:

61A 16 =110 0001 1010 2
11 1110 0111 2 =3E7 16 .

The octal number system has eight digits: 0, 1, 2, 3, 4, 5, 6, 7. Converting from this system to binary is quite simple. It is enough to make a table of triads (three digits each).

When converting an octal number to binary, replace each octal digit with the corresponding triad from the table (see examples in the card).

For the reverse operation, that is, to convert from binary to octal, the binary number is divided into triads (from right to left), then each group is replaced by one octal digit.

Similarly, we convert from hexadecimal to binary systems and vice versa.

b) I suggest that the guys compete with each other “Who is faster” to consolidate their skills; in addition to speed, attentiveness and accuracy play a big role here.

    • Let's write the numbers in the octal number system so that there are 17 of them: 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17, 20 (in this number In the series after the number 7, the digit is exceeded since the number 8 does not exist, we move from the units category to the tens category and so on). It is no coincidence that we needed these numbers, because we will consider the coordinate plane for the octal number system. You will be given the coordinates of the drawing in the binary coordinate system, and the drawing must be done in the octal system. Connect the points in the order they appear.
    • I distribute cards with coordinates (2-4 options) and the first point (arbitrary) is shown with an example (on the board: by writing out the coordinates and showing them on the coordinate plane). Examples of tables with coordinates:

Option 1.

Option 2.

    • The first 2-3 people who complete the task correctly (the picture matches the original) receive a grade of “5”.

Examples of drawings - answers:

/p>

Figure 2

Figure 3

  1. For homework, I ask you to draw a picture in the hexadecimal number system and write the coordinates in a table in the binary system.
  2. So we looked at several ways to translate numbers: general and particular. Some of them required you to be able to solve problems using mathematical methods, others with the use of a computer, and others with the use of triads and tetrads. Thus, we repeated the topic “Translations of numbers in different number systems” and prepared for the test. Good luck. Goodbye!

Used Books:

  1. Encyclopedia for children. Volume 22. Computer Science/Chapter. ed. E. A. Khlebalina, leading scientific ed. A.G. Leonov. - M.: Avanta+, 2003. – 624 p.: ill.
  2. Efimova O., Morozov V., Ugrinovich N. Course of computer technologies with the basics of computer science. Textbook for high school. –M.: LLC “AST Publishing House”; ABF, 2000. – 432 pp.: ill.

The calculator allows you to convert whole and fractional numbers from one number system to another. The base of the number system cannot be less than 2 and more than 36 (10 digits and 26 Latin letters after all). The length of numbers must not exceed 30 characters. To enter fractional numbers, use the symbol. or, . To convert a number from one system to another, enter the original number in the first field, the base of the original number system in the second, and the base of the number system to which you want to convert the number in the third field, then click the "Get Record" button.

Original number written in 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 -th number system.

I want to get a number written in 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 -th number system.

Get entry

Translations completed: 1237177

Number systems

Number systems are divided into two types: positional And not positional. We use the Arabic system, it is positional, but there is also the Roman system - it is not positional. In positional systems, the position of a digit in a number uniquely determines the value of that number. This is easy to understand by looking at some number as an example.

Example 1. Let's take the number 5921 in the decimal number system. Let's number the number from right to left starting from zero:

The number 5921 can be written in the following form: 5921 = 5000+900+20+1 = 5·10 3 +9·10 2 +2·10 1 +1·10 0 . The number 10 is a characteristic that defines the number system. The values ​​of the position of a given number are taken as powers.

Example 2. Consider the real decimal number 1234.567. Let's number it starting from the zero position of the number from the decimal point to the left and right:

The number 1234.567 can be written in the following form: 1234.567 = 1000+200+30+4+0.5+0.06+0.007 = 1·10 3 +2·10 2 +3·10 1 +4·10 0 +5·10 -1 + 6·10 -2 +7·10 -3 .

Converting numbers from one number system to another

The simplest way to convert a number from one number system to another is to first convert the number to the decimal number system, and then the resulting result to the required number system.

Converting numbers from any number system to the decimal number system

To convert a number from any number system to decimal, it is enough to number its digits, starting with zero (the digit to the left of the decimal point) similarly to examples 1 or 2. Let's find the sum of the products of the digits of the number by the base of the number system to the power of the position of this digit:

1. Convert the number 1001101.1101 2 to the decimal number system.
Solution: 10011.1101 2 = 1·2 4 +0·2 3 +0·2 2 +1·2 1 +1·2 0 +1·2 -1 +1·2 -2 +0·2 -3 +1·2 - 4 = 16+2+1+0.5+0.25+0.0625 = 19.8125 10
Answer: 10011.1101 2 = 19.8125 10

2. Convert the number E8F.2D 16 to the decimal number system.
Solution: E8F.2D 16 = 14·16 2 +8·16 1 +15·16 0 +2·16 -1 +13·16 -2 = 3584+128+15+0.125+0.05078125 = 3727.17578125 10
Answer: E8F.2D 16 = 3727.17578125 10

Converting numbers from the decimal number system to another number system

To convert numbers from the decimal number system to another number system, the integer and fractional parts of the number must be converted separately.

Converting an integer part of a number from a decimal number system to another number system

An integer part is converted from a decimal number system to another number system by sequentially dividing the integer part of a number by the base of the number system until a whole remainder is obtained that is less than the base of the number system. The result of the translation will be a record of the remainder, starting with the last one.

3. Convert the number 273 10 to the octal number system.
Solution: 273 / 8 = 34 and remainder 1. 34 / 8 = 4 and remainder 2. 4 is less than 8, so the calculation is complete. The record from the balances will look like this: 421
Examination: 4·8 2 +2·8 1 +1·8 0 = 256+16+1 = 273 = 273, the result is the same. This means the translation was done correctly.
Answer: 273 10 = 421 8

Let's consider the translation of regular decimal fractions into various number systems.

Converting the fractional part of a number from the decimal number system to another number system

Recall that a proper decimal fraction is called real number with zero integer part. To convert such a number to a number system with base N, you need to sequentially multiply the number by N until the fractional part goes to zero or the required number of digits is obtained. If, during multiplication, a number with an integer part other than zero is obtained, then the integer part is not taken into account further, since it is sequentially entered into the result.

4. Convert the number 0.125 10 to the binary number system.
Solution: 0.125·2 = 0.25 (0 is the integer part, which will become the first digit of the result), 0.25·2 = 0.5 (0 is the second digit of the result), 0.5·2 = 1.0 (1 is the third digit of the result, and since the fractional part is zero , then the translation is completed).
Answer: 0.125 10 = 0.001 2

Those taking the Unified State Exam and more...

It is strange that in computer science lessons in schools they usually show students the most complex and inconvenient way to convert numbers from one system to another. This method consists of sequentially dividing the original number by the base and collecting the remainders from the division in reverse order.

For example, you need to convert the number 810 10 to binary:

We write the result in reverse order from bottom to top. It turns out 81010 = 11001010102

If you need to convert fairly large numbers into the binary system, then the division ladder takes on the size of a multi-story building. And how can you collect all the ones and zeros and not miss a single one?

The Unified State Exam program in computer science includes several tasks related to converting numbers from one system to another. Typically, this is a conversion between octal and hexadecimal systems and binary. These are sections A1, B11. But there are also problems with other number systems, such as in section B7.

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

Table of powers 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 of these numbers, the rest are not difficult to obtain in your mind from those that you remember.

Table of binary numbers from 0 to 15 with hexadecimal representation:

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.

Integer conversion

So, let's start by converting directly to the binary system. Let's take the same number 810 10. We need to decompose this number into terms equal to powers of two.

  1. We are looking for the power of two closest to 810 and not exceeding it. This is 2 9 = 512.
  2. Subtract 512 from 810, we get 298.
  3. Repeat steps 1 and 2 until there are no 1s or 0s left.
  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 methods, you can use any 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, the cube 1000. That is, the degree of the base of the number system is 1 (one), and there are as many zeros behind it as the degree is.

Method 1: Arrange 1 according to the ranks of the indicators of the terms. In our example, these are 9, 8, 5, 3 and 1. The remaining places will contain zeros. So, we got the binary representation of the number 810 10 = 1100101010 2. Units are placed in 9th, 8th, 5th, 3rd and 1st places, counting from right to left from zero.

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

810 =

Now let's add these steps together, like folding a fan: 1100101010.

That's all. At the same time, 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 this representation. 810 has 5 of them.

Now the example is simpler.

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

Let's convert the number 547 8 to binary.

547 8 = 101 100 111
5 4 7

One more, for example 7D6A 16.

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

Let's convert the number 7368 to the hexadecimal system. First, write the numbers in triplets, and then divide them into quadruples from the end: 736 8 = 111 011 110 = 1 1101 1110 = 1DE 16. Let's convert the number C25 16 to the octal 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. It is not difficult, the main thing is not to make mistakes in the calculations. We expand the number into a polynomial with powers of the base and coefficients for 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 .

Converting Negative Numbers

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

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

We convert 79 to the binary system, 79 = 1001111. We add zeros on the left to the size of the byte, 8 bits, we get 01001111. We 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 Unified State Exam question “how many units are in the binary representation of the number -79?” The answer is 4.

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

Converting fractional numbers

Fractional numbers are converted in the reverse way of dividing whole numbers by the base, which we looked at at the very beginning. That is, using sequential multiplication by a new base with the collection of whole parts. The integer 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 integer and fractional parts are translated separately and then glued together.

Let's convert the number 0.6752 to the 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 the 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.