Hexadecimal and binary number systems. Hex code

Originated in ancient Babylon. In India, the system works in the form of positional decimal numbering using zero; the Arab nation borrowed this number system from the Indians, and the Europeans, in turn, took it from them. In Europe, this system began to be called Arabic.

Positional systemdead reckoning— the meaning of all digits depends on the position (digit) of the given digit in the number.

Examples, the standard decimal number system is a positional system. Let's say given a number453 . Number 4 stands for hundreds and corresponds to a number400, 5 - number of tens and corresponds to the value50 , A 3 - units and meaning3 . It is easy to see that as the digit increases, the value increases. Thus, we write the given number as a sum400+50+3=453.

Hexadecimal number system.

Hexadecimal number system(hexadecimal numbers) - positional number system. Hexadecimal base is the number 16.

By writing numbers in the octal number system we get fairly compact expressions, but in the hexadecimal system we get more compact expressions.

The first ten digits of the sixteen hexadecimal digits are standard spacing 0 - 9 , the next six digits are expressed using the first letters of the Latin alphabet: A, B, C, D, E, F. Conversion from hexadecimal to binary and vice versa is similar to the process for octal.

Application of the hexadecimal number system.

The hexadecimal number system is quite well used in modern computers, For example use it to indicate color: #FFFFFF- White color.

Converting numbers from one number system to another.

Converting numbers from hexadecimal to decimal.

To convert a hexadecimal number to a decimal number, you need to reduce the given number to the form of the sum of the products of the powers of the base of the hexadecimal number system by the corresponding digits in the digits of the hexadecimal number.

For example, convert the hexadecimal number 5A3 to decimal. Here 3 numbers. Based on the above rule, we reduce it to the form of a sum of powers with a base of 16:

5A3 16 = 3·16 0 +10·16 1 +5·16 2 = 3·1+10·16+5·256 = 3+160+1280 = 1443 10

Converting numbers from binary to hexadecimal and vice versa.

To convert a multi-digit binary number to hexadecimal, you need to divide it into tetrads from right to left and replace all tetrads with the corresponding hexadecimal digit. To convert a number from the hexadecimal system to the binary system, you need to change each digit to the corresponding tetrads from the conversion table, which you will find below.

For example:

010110100011 2 = 0101 1010 0011 = 5A3 16

Number conversion table.

An algorithm for converting numbers from one number system to another.

1. From the decimal number system:

  • divide the number by the base of the translated number system;
  • find the remainder when dividing the 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, we find the sum of the products of base 2 by the corresponding degree of digit;
  • To convert a number to octal, we divide the number into triads.

For example, 1000110 = 1,000 110 = 1068

  • To convert a number from the binary number system to hexadecimal, we divide the number into groups of 4 digits.

For example, 1000110 = 100 0110 = 4616.

Translation tables:

Binary SS

Hexadecimal SS

0000

0001

0010

0011

0100

0101

0110

0111

1000

1001

1010

1011

1100

1101

1110

1111

Binary SS

Many computer users understand that a computer operates in a binary number system. Traditionally, the states of a binary system are represented by the numbers 0 and 1, although, more precisely, each state indicates the presence or absence of a signal, i.e. it would be more correct to call the states “off” and “on”, or “no” and “yes”. The state “off” or “no” corresponds to the number 0, and the state “on” or “yes” corresponds to the number 1. Ordinary users usually do not need to fully understand the structure of the computer, however, the binary number system makes itself felt in the form of various restrictions based on powers of two . A more compact version of the binary system is called hexadecimal. The number sixteen is the fourth power of two. It follows from this that you can quite simply convert long binary sequences of zeros and ones into short hexadecimal ones. To do this, simply split the binary sequence into groups of four digits (digits) starting with the least significant digit (on the right) and replace each group with the corresponding hexadecimal value.

The hexadecimal system is usually used for the convenience of perceiving binary data, since conversions from the hexadecimal system to the binary system and back are carried out by simply replacing strings. The computer works exclusively with binary sequences, and the hexadecimal notation of this sequence is four times more compact, since this system has base 16 (2 16), and binary 2. The binary sequence can be quite cumbersome. For example, writing the number 513 requires ten binary digits (1000000001), but only three in hexadecimal (201). However, to represent any hexadecimal number, sixteen different symbols are required, rather than the ten that are used in the decimal number system we are familiar with. The first ten characters are characters in the range from 0 to 9, the rest are letters of the Latin alphabet in the range from A to F. The letters are usually (but not always) written in uppercase (capital) in hexadecimal notation of the number. The first ten characters (from 0 to 9) are written similarly to numbers in the decimal number system and correspond to them. Letters in the range A through F correspond to values ​​in the range 10 to 15.

Let's consider the correspondence of numbers from 0 to 15 in hexadecimal and binary number systems.

Decimal notation Hexadecimal notation Binary notation
0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110
7 7 0111
8 8 1000
9 9 1001
10 A 1010
11 B 1011
12 C 1100
13 D 1101
14 E 1110
15 F 1111

The entries for 10, 11, etc. in decimal, binary, and hexadecimal systems do not correspond to each other. Let's look at a small example. Let us have a hexadecimal number 1A5E. To convert to binary, simply replace the hexadecimal digits with the corresponding binary groups. The result is 0001 1010 0101 1110. If we remove the insignificant zeros in front of the number and write it without separators, we get 1101001011110. For the reverse translation, we divide the number into groups of four digits, starting with the lowest (on the right side), and also for convenience we add insignificant zeros in the highest group to 4 ranks. We get 0001 1010 0101 1110. Replace the groups with the corresponding hexadecimal values, we get 1A5E.

To convert a hexadecimal number into a decimal representation, you can use the scheme by which we write decimal numbers. In a decimal number, each digit represents the corresponding power of ten, starting from zero and increasing from right to left. For example, the decimal number 123 means 1*10 2 + 2*10 1 + 3*10 0 . Using a similar method, we convert the number 1A5E to the decimal number system. In the hexadecimal number system, as well as in the decimal number system, each digit denotes the corresponding power of the number sixteen, starting from zero and increasing from right to left. The characters 1 and 5 in hexadecimal correspond to the values ​​1 and 5 in decimal, and the characters A and E correspond to 10 and 14. Then 1A5E can be represented in decimal as 1*16 3 + 10*16 2 + 5*16 1 + 14*16 0 = 6750. However, to evaluate hexadecimal numbers it is not at all necessary to convert them to decimal. The rules for comparison, addition and multiplication in this system are the same as in the decimal system, the main thing is not to forget that each digit can contain values ​​​​from 0 to 15. To quickly convert numbers between number systems, you can use a standard calculator in Windows, for this it is enough to In the advanced mode of the calculator, select a number system, enter a number in it and select the desired number system in which to display the result.

Because numeric-only hexadecimal numbers are easily confused with decimal numbers, they are usually marked in a way that makes it clear that hexadecimal notation is used. Hexadecimal entries are usually marked by either adding a lowercase "h" to the end or adding a "0x" prefix before the number. Thus, the hexadecimal number 1A5E can be written as 1A5Eh or 0x1A5E, where a trailing “h” or a leading “0x” indicates that hexadecimal notation is used.