How to convert from binary to 16. Hexadecimal code

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 into reverse order.

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

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

If you need to convert to the binary system, quite big numbers, 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?

IN Unified State Exam program in computer science includes several tasks related to the translation of 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 additional 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.

For translate negative number in binary's complement code 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.

Translation 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 whole parts obtained by multiplication are collected, but do not participate in 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.

Converting numbers from one number system to another is important part machine arithmetic. Let's consider the basic rules of translation.

1. To convert a binary number to a decimal one, 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 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 number 2

n (degree)

Example.

2. For translation octal number in 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 eight:

Table 5. Powers of the number 8

n (degree)

Example. Convert the number to the decimal number system.

3. To convert a hexadecimal number to a decimal one, 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 16, and calculate it according to the rules of decimal arithmetic:

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

Table 6. Powers of the number 16

n (degree)

Example. Convert the number to the decimal number system.

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

Example. Convert the number to the binary number system.

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

Example. Convert the number to hexadecimal number system.

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, click on the image right click

mouse 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 can be represented as the sum of the terms of the 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. More perfect non-positional systems number systems were alphabetic 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

Hexadecimal number system(also known as hexadecimal code) is a positional number system with an integer base of 16. The term hex (pronounced hex, short for English hexadecimal) is also sometimes used in the literature. The digits of this number system are usually used in Arabic numerals 0-9, as well as the first characters of the Latin alphabet A-F. The letters correspond to the following decimal values:

  • * A -10;
  • *B—11;
  • *C—12;
  • * D -13;
  • * E - 14;
  • * F - 15.

Thus, ten Arabic numerals, coupled with six Latin letters, make up the sixteen digits of the system.

By the way, on our website you can convert any text into decimal, hexadecimal, binary code using the Online Code Calculator.

Application. Hex code widely used in low-level programming as well as in various computer reference documents. The popularity of the system is justified architectural solutions modern computers: in them as minimum unit information is set to a byte (consisting of eight bits) - and the byte value is conveniently written using two hexadecimal digits. The byte value can range from #00 to #FF (0 to 255 in decimal notation) - in other words, using hexadecimal code, you can write any state of the byte, while there are no “extra” digits not used in the recording.

Encoded Unicode Four hexadecimal digits are used to record the character number. The RGB color notation (Red, Green, Blue) also often uses hexadecimal code (for example, #FF0000 is a bright red color notation).

A method for writing hexadecimal code.

Mathematical way of writing. In mathematical notation, the base of the system is written in decimal form as a subscript to the right of the number. The decimal notation of the number 3032 can be written as 3032 10, in hexadecimal notation given number will have the entry BD8 16.

In the syntax of programming languages. Syntax various languages programming sets the format for writing a number using hexadecimal code:

* The syntax of some varieties of assembly language uses the Latin letter “h”, which is placed to the right of the number, for example: 20Dh. If a number begins with a Latin letter, then a zero is placed in front of it, for example: 0A0Bh. This is done in order to distinguish values ​​using constants from constants. hexadecimal code;

* Other types of assembler, as well as Pascal (and its variants such as Delphi) and some Basic dialects, use the "$" prefix: $A15;

* In language HTML markup, as well as in cascade CSS files, to specify the color in RGB format with hexadecimal notation, the prefix “#” is used: #00DC00.

How to convert hexadecimal code to another system?

Convert from hexadecimal to decimal. To perform a conversion operation from the hexadecimal system to the decimal system, you need to represent the original number as the sum of the products of the digits in the digits of the hexadecimal number and the power of the base.

Binary SS

hex SS

For example, you need to translate the hexadecimal number A14: it has three digits. Using the rule, we write it as a sum of powers with a base of 16:

A14 16 = 10.16 2 + 1.16 1 + 4.16 0 = 10.256 + 1.16 + 4.1 = 2560 + 16 + 4 = 2580 10

Converting numbers from binary to hexadecimal and vice versa.

A notebook table is used for translation. To convert a number from the binary to the decimal system, you need to split it into separate tetrads from right to left, and then, using the table, replace each tetrad with the corresponding hexadecimal digit. Moreover, if the number of digits is not a multiple of four, then it is necessary to add the corresponding number of zeros to the right of the number in order to total number binary digits became a multiple of four.

Table of notebooks for translation.

To convert from hexadecimal to binary, you need to do reverse operation: replace each digit with a notebook from the table.

Binary SS

Octal SS

Example conversion from hexadecimal to binary: A5E 16 = 1010 0101 1110 = 101001011110 2

Example conversion from binary to hexadecimal: 111100111 2 = 0001 1110 0111 = 1E7 16

In this example, the number of digits in the original binary number was not equal to four (9), so non-significant zeros were added - the total number of digits became 12.

Automatic translation. Quick transfer from hexadecimal number system to one of three popular systems(binary, octal and decimal), as well as reverse translation, can be done using standard calculator supplied with Windows OS. Open the calculator, select View -> Programmer from the menu. IN this mode you can set the number system used in this moment(see menu on the left: Hex, Dec, Oct, Bin). In this case, changing the current number system automatically produces a translation.

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 greater 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, radix original system number into the second and the base of the number system into which you want to convert the number into 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

Most in a simple way converting a number from one number system to another is to first convert the number into a decimal number system, and then the resulting result into 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 remainder will have next view: 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

Consider the translation of proper decimal fractions into various systems Reckoning.

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

Let us remind you that the correct decimal called real number with zero integer part. To convert such a number into a number system with base N, you need to sequentially multiply the number by N until fraction will not reset or the required number of digits will not be received. 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