• From 10 to 16 online system. Binary octal hexadecimal number system

    1. Ordinal counting in various number systems.

    IN modern life we use positional number systems, that is, systems in which the number denoted by a digit depends on the position of the digit in the notation of the number. Therefore, in the future we will talk only about them, omitting the term “positional”.

    In order to learn how to convert numbers from one system to another, we will understand how sequential recording of numbers occurs using the example of the decimal system.

    Since we have a decimal number system, we have 10 symbols (digits) to construct numbers. We start counting: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. The numbers are over. We increase the bit depth of the number and reset the least significant digit: 10. Then we increase the low digit again until all the digits are gone: 11, 12, 13, 14, 15, 16, 17, 18, 19. We increase the high digit by 1 and reset the low digit: 20. When we use all the digits for both digits (we get the number 99), we again increase the digit capacity of the number and reset the existing digits: 100. And so on.

    Let's try to do the same in the 2nd, 3rd and 5th systems (we introduce the notation for the 2nd system, for the 3rd, etc.):

    0 0 0 0
    1 1 1 1
    2 10 2 2
    3 11 10 3
    4 100 11 4
    5 101 12 10
    6 110 20 11
    7 111 21 12
    8 1000 22 13
    9 1001 100 14
    10 1010 101 20
    11 1011 102 21
    12 1100 110 22
    13 1101 111 23
    14 1110 112 24
    15 1111 120 30

    If the number system has a base greater than 10, then we will have to enter additional characters; it is customary to enter letters of the Latin alphabet. For example, for the 12-digit system, in addition to ten digits, we need two letters ( and ):

    0 0
    1 1
    2 2
    3 3
    4 4
    5 5
    6 6
    7 7
    8 8
    9 9
    10
    11
    12 10
    13 11
    14 12
    15 13

    2. Conversion from the decimal number system to any other.

    To convert a positive integer decimal number to a number system with a different base, you need to divide this number by the base. Divide the resulting quotient by the base again, and further until the quotient is less than the base. As a result, write down in one line the last quotient and all remainders, starting from the last.

    Example 1. Let's convert the decimal number 46 to binary system Reckoning.

    Example 2. Let's convert the decimal number 672 to octal system Reckoning.

    Example 3. Let's convert the decimal number 934 to the hexadecimal number system.

    3. Conversion from any number system to decimal.

    In order to learn how to convert numbers from any other system to decimal, let's analyze the usual notation for a decimal number.
    For example, the decimal number 325 is 5 units, 2 tens and 3 hundreds, i.e.

    The situation is exactly the same in other number systems, only we will multiply not by 10, 100, etc., but by the powers of the base of the number system. For example, let's take the number 1201 in the ternary number system. Let's number the digits from right to left starting from zero and imagine our number as the sum of the products of a digit and three to the power of the digit of the number:

    This is the decimal notation of our number, i.e.

    Example 4. Let's convert to decimal system octal number 511.

    Example 5. Let's convert the hexadecimal number 1151 to the decimal number system.

    4. Conversion from the binary system to the system with the base “power of two” (4, 8, 16, etc.).

    To convert a binary number to a number with the base “power of two”, it is necessary to divide the binary sequence into groups according to the number of digits equal to the power from right to left and replace each group with the corresponding digit new system Reckoning.

    For example, Let's convert the binary number 1100001111010110 to the octal system. To do this, we will divide it into groups of 3 characters starting from the right (since ), and then use the correspondence table and replace each group with a new number:

    We learned how to build a correspondence table in step 1.

    0 0
    1 1
    10 2
    11 3
    100 4
    101 5
    110 6
    111 7

    Those.

    Example 6. Let's convert the binary number 1100001111010110 to hexadecimal.

    0 0
    1 1
    10 2
    11 3
    100 4
    101 5
    110 6
    111 7
    1000 8
    1001 9
    1010 A
    1011 B
    1100 C
    1101 D
    1110 E
    1111 F

    5. Conversion from a system with the base “power of two” (4, 8, 16, etc.) to binary.

    This translation is similar to the previous one, made in reverse side: We replace each digit with a group of binary digits from the lookup table.

    Example 7. Let's convert the hexadecimal number C3A6 to the binary number system.

    To do this, replace each digit of the number with a group of 4 digits (since ) from the correspondence table, supplementing the group with zeros at the beginning if necessary:



    Hexadecimal number system(Also - hexadecimal code) is positional system Numbers with an integer base 16. Sometimes in the literature the term hex is also used (pronounced “hex”, short for the English hexadecimal). 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 by architectural solutions modern computers: They have a byte (consisting of eight bits) as the minimum unit of information - and the value of a byte 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. Decimal notation the numbers 3032 can be written as 3032 10; in hexadecimal, this number will have the notation BD8 16.

    In the syntax of programming languages. Syntax different 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 hexadecimal number to the degree of foundation.

    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 for the total number binary digits became a multiple of four.

    Table of notebooks for translation.

    To convert from hexadecimal to binary, you need to perform the reverse operation: replace each digit with a tetrad 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 four (9), so leading zeros were added for a total of 12 digits.

    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 performed 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 at the moment(see menu on the left: Hex, Dec, Oct, Bin). In this case, changing the current number system automatically produces a translation.

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

    Translation of integers 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

    Converting numbers from 2, 8 and 16 to the decimal system is done 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 it serial number in the translated number. In this case, the numbers are numbered to the left of the decimal point (the first number is numbered 0) with increasing, and to the right 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 SSHexadecimal 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

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

    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.

    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 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 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 it. Along the way, the problem of “how many units in binary notation number 810?

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

    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.