Convert the decimal number to hexadecimal number system. Converting numbers from hexadecimal to decimal


Converting numbers from hexadecimal system to decimal

Richnaya

Hexadecimal number system (hexadecimal numbers) is a positional number system based on integer base 16. Typically used as hexadecimal digits decimal digits from 0 to 9 and letters A to F to represent numbers from 1010 to 1510, i.e. (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F).

To convert a hexadecimal number to a decimal number, it is necessary to present this number as 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, you need to translate hexadecimal number 5A3 to decimal. This number has 3 digits. In accordance with the above rule, we present it as a sum of powers with a base of 16:

5A316 = 3 160+10 161+5 162

3 1 + 10 16 + 5 256 = 3 + 160 + 1280 = 144310

Converting decimal numbers to binary

Let's say we need to convert the number 19 to binary. You can use the following procedure:

19 /2 = 9 with remainder 1

9 /2 = 4 with remainder 1

4 /2 = 2 without remainder 0

2 /2 = 1 without remainder 0

1 /2 = 0 with remainder 1

So we divide each quotient by 2 and write the remainder at the end of the binary notation. We continue dividing until the quotient is 0. We write the result from right to left. Those. the bottom number will be the leftmost one, etc. As a result, we get the number 19 in binary notation: 10011.

Converting Decimal Numbers to Ternary Numbers

Consistently divide first the number, and then the quotients from division by 3 until the next quotient becomes less than 3, and write down the remainders from right to left. At the end, add the last quotient.

38: 3 = 12 rest 2

12: 3 = 4 rest 0

4: 3 = 1 rest 1

Total 38(10) = 1102(3)

Converting decimal numbers to octal

To convert numbers from decimal system Numbers to octal use the same “substitution algorithm” as when converting from decimal to binary, only 8, the base of the octal number system, is used as the divisor:

We divide decimal number And by 8. We remember the quotient Q for the next step, and write the remainder a as the least significant bit of an octal number.

If the quotient q is not equal to 0, we take it as the new dividend and repeat the procedure described in step 1. Each new remainder is written into the octal digits in the direction from the least significant bit to the most significant one.

The algorithm continues until, as a result of steps 1 and 2, the quotient Q = 0 and the remainder a is less than 8.

For example, you want to convert the decimal number 3336 to octal. In accordance with the above algorithm we get: 333610: 8 = 41710


333610 - 333610 = 0, the remainder 0 is written in MB of the octal number.

41710 - 41610 = 1, the remainder 1 is written in the next digit of the octal number after MB.

5210 - 4810 = 4, the remainder 4 is written in the most significant digit of the octal number.

610: 8 = 010, remainder 0, write 6 to the most significant digit of the octal number.

Thus, what we are looking for octal number equals 64108.

Converting decimal numbers to hexadecimal

To convert numbers from the decimal number system to hexadecimal, the same “substitution algorithm” is used as when converting from the decimal number system to binary and octal, only 16, the base of the hexadecimal number system, is used as a divisor:

We divide the decimal number A by 16. We remember the quotient Q for the next step, and write the remainder a as the least significant bit of the hexadecimal number.

If the quotient q is not equal to 0, we take it as the new dividend and repeat the procedure described in step 1. Each new remainder is written to the digits of the hexadecimal number in the direction from the least significant bit to the most significant one.

The algorithm continues until, as a result of steps 1 and 2, the quotient Q = 0 and the remainder a is less than 16.

For example, you want to convert the decimal number 32767 to hexadecimal. In accordance with the above algorithm we get: 3276710: 16 = 204710

3276710 - 3275210 = 15, the remainder 15 in the form F is written in MB of hexadecimal number.

204710: 16 = 12710

204710 - 203210 = 15, the remainder 15 in the form F is written in the hexadecimal digit next after MB.

12710 - 11210 = 15, the remainder 15 in the form F is written in the most significant digit of the hexadecimal number.

710: 16 = 010, the remainder 7 is written in the most significant digit of the hexadecimal number.

Thus, the hexadecimal number we are looking for is 7FFF16.

Examples

134 = 10000110 2

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 new system numbering until the remainder remains a number smaller than the base of the new number system. The new number is written as division remainders, starting from the last one.
Converting a correct 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 it reaches specified accuracy translation. 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. Kisses and fractional part 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 binary system To calculate octal (hexadecimal) numbers, it is necessary to divide the binary number from the comma 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

Laboratory work №1

Topic: Number system. Converting integer decimal numbers to binary, octal, hexadecimal number systems. (1 hour), SRSP (1 hour).

Decimal number system

The name "decimal" comes from the fact that this system is based on the base ten. This system uses ten digits to write numbers - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.

The decimal system is positional because the meaning of a digit in a decimal number depends on its position, or location, in the number.

The position allocated for the digit of a number is called digit.

For example, the entry 526 means that the number consists of 5 hundreds, 2 tens and 6 ones. The number 6 is in the units place. The number 2 is in the tens place and the number 5 is in the hundreds place.

Write this number as a sum:

526=5*10 2 +2*10 1 +6*10 0

in this entry the number 10 is the base of the number system. For each digit of a number, base 10 is raised to a power depending on the position of the digit and multiplied by that digit. The base power for units is zero, for tens it is one, for hundreds it is two, etc.

Negative exponents are used to write decimal fractions. For example, the number 555.55 in expanded form is written as follows:

555.55 10 = 5*10 2 + 5*10 1 + 5*10°+ 5*10- 1 +5*10- 2 .:

Converting integer decimal numbers to the binary number system.

When converting a decimal number to binary, you need to divide this number by 2. To convert an integer positive decimal number to the binary number system, you need to divide this number by 2. The resulting quotient is again divided by 2, etc. until the quotient is less than 2. As a result, write down the last quotient and all remainders, starting from the last, in one line.

Example. Convert the number 891 from the decimal system to the binary number system.

Solution:

1:2=0, 1 (most significant digit binary number)

We write down the last quotient and all remainders, starting from the last, in one line.



Answer: 891 10 =1101111011 2

Converting decimal fractions to binary number system

Converting decimal fractions to the binary number system involves finding the whole parts when multiplying by 2.

Example. Let's convert the decimal fraction 0.322 to the binary number system.

To find the first digit after the decimal point of a binary fraction, you need to multiply the given number by 2 and select the integer part of the product.

Solution:

0,322 10 8,83 10

0.322*2=0.644 0 8:2=4 remainder 0

0.644*2=1.288 1 4:2=2 remainder 0

0.288*2=0.576 0 2:2=1 remainder 0

0.576*2=1.152 1 1:2=0 remainder 1

0.3222 10 =0.0101 2 0.83*2=1.66 the integer part is 1

0.66*2=1.32 the integer part is 1

0.32*2=0.64 the integer part is 0

0.64*2=1.28 the integer part is 1

Answer: 8.83=1000.1101

Converting decimal numbers to octal number system

To convert a number from the decimal system to octal, the same technique is used as when converting to the binary system.

The converted number is divided by 8 according to the rules of the decimal system, storing the remainder, which, of course, does not exceed 7. If the resulting quotient is greater than 7, it is also divided by 8, retaining the remainder.

Solution:

(most significant digit of a binary number).

Answer: 891 10 =1573 8

Converting decimal numbers to hexadecimal number system

They convert a decimal number to a hexadecimal number in the same way, with the only difference being that instead of 8, this number is divided by 16.

Example: Convert the number 891 from the decimal system to the hexadecimal number system.

Solution: remainder

Independent work student with teachers:

1. Task: Present the sum of the powers of the base of the number:

1. 425 10 8. 3678,898 10

2. 256 10 9. 7,29083 10

3. 852 10 10. 0,0032 10

4. 1243 10 11. 2,3589 10

5. 2569 10 12. 48,965 10

6. 4568 10 13. 56,897 10

7. 12568 10 14. 48,975 10

2. Task: Convert decimal numbers to the binary number system:

323 10 8. 125 10

150 10 9. 229 10

283 10 10. 88 10

428 10 11. 255 10

315 10 12. 325 10

181 10 13. 259 10

176 10 14. 652 10

3. Task: Convert fractional decimal numbers to the binary number system:

0,322 10 8. 37,25 10

150,7006 10 9. 206,125 10

283,245 10 10. 0,386 10

0,428 10 11. 10,103 10

315,075 10 12. 8,83 10

181,369 10 13. 14,125 10

176,526 10 14. 15,75 10

4. Task: Convert decimal numbers to the octal number system:

1. 322 10 8. 7006 10

2. 524 10 9. 125 10

3. 283,245 10 10. 229 10

4. 428 10 11. 88 10

5. 315,075 10 12. 37,25 10

6. 181,369 10 13. 206,125 10

7. 176,526 10 14. 940 10

5. Task: Convert decimal numbers to hexadecimal number system:

1. 322 10 8. 369 10

2. 150,7006 10 9. 125 10

3. 283,245 10 10. 229 10

4. 428 10 11. 88 10

5. 315,075 10 12. 37,25 10

6. 181 10 13. 206,125 10

7. 176,526 10 14. 98,93 10

Control questions:

1. What is a number system called?

2. What is the difference between positional number systems and non-positional ones?

3. What is called the base of the positional number system?

4. What is a discharge?

Laboratory work No. 2

Topic of the lesson: Binary number system. Converting numbers from binary to octal and hexadecimal. Arithmetic operations on binary numbers. (1 hour), SRS (2 hours).

Computers, as a rule, use not a decimal number system, but a positional binary number system, i.e. number system with base 2. In the binary system, any number is written using two digits 0 and 1 and is called a binary number.

In order to distinguish a binary number from a decimal number containing only the digits 0 and 1, a sign of the binary number system is added to the entry of the binary number in the index, for example 110101,111 2. Each digit (digit) of a binary number is called a bit.

Like a decimal number, any binary number can be written as a sum, which clearly reflects the difference in the weights of the digits included in the binary number 2. For example, for the binary number 1010101.101, the sum will take the form

1010101,101 2 =1*2 6 +0*2 5 +1*2 4 +0*2 3 +1*2 2 +0*2 1 +1*2 0 +1*2 -1 +0*2 -2 +1*2 -3

This amount is written using the same rules as the amount for a decimal number. IN in this example A binary number has a seven-digit integer part and a three-digit fractional part. Therefore, the most significant digit of the integer part, i.e. one is multiplied by 2 7-1 = 2 6, the next digit of the integer part, equal to zero, is multiplied by 2 5, etc. in descending powers of two to the lowest, third, digit of the fractional part, which will be multiplied by 2 -3. Performing arithmetic operations on this sum according to the rules of the decimal system, we obtain the decimal number 85.625. So the binary number 1010101.101 is the same as the decimal number 85.625 or 1010101.101=85.625 10

1. 11100011 2 =1×2 7 +1×2 6 +1×2 5 +0×2 4 +0×2 3 +0×2 2 +1×2 1 +1×2 0 = 128+64+32 +2+1=227 10

2. 0.10100011 2 =1×2 -1 +0×2 -2 +1×2 -3 +0×2 -4 +0×2 -5 +0×2 -6 +1×2 -7 +1 ×2 -8 =0.5+0.125+0.0078+0.0039 =0.6367 10

After studying the previous section, reformulating the algorithm for converting numbers from hexadecimal to decimal number system is not difficult. You should only remember that for the hexadecimal number system the base is the number 16 , and the translation rule into in this case can be formulated as follows:

To convert a hexadecimal number to a decimal number, it is necessary to present this number as 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, you need to convert a hexadecimal number F45ED23C to decimal. In this number 8 numbers and 8 bits (remember that bits are counted starting from zero, which corresponds to the least significant bit). In accordance with the above rule, we present it as a sum of powers with a base 16 :

F45ED23C 16 = (15 16 7 )+(4·16 6 )+(5·16 5 )+(14·16 4 )+(13·16 3 )+(2·16 2 )+(3·16 1 )+(12·16 0 ) = = 4099854908 10

For manual calculations and solving examples and test tasks, you may find the tables of powers of the bases of the number systems being studied (2, 8, 10, 16) given in the Appendix useful.

Converting numbers from decimal to binary

To convert numbers from the decimal number system to the binary number system, the so-called “substitution algorithm” is used, consisting of the following sequence of actions:

    Divide a decimal number A on 2 . Private Qa write it down as Jr bit of a binary number.

    If private q not equal 0 , take it as a new dividend and repeat the procedure described in step 1. Each new remainder ( 0 or 1 ) is written into the bits of a binary number in the direction from junior bit to eldest .

    Q=0 and the remainder a=1 .

247 to binary. In accordance with the above algorithm we obtain:

247 10 : 2 = 123 10

247 10 -246 10 =1 , remainder 1 write in MB binary number.

123 10 : 2 = 61 10

123 10 -122 10 =1 , remainder 1 write in the next one after MB bit of a binary number.

61 10 : 2 = 30 10

61 10 -60 10 =1 , remainder 1

30 10 : 2 = 15 10

30 10 -30 10 =0 , remainder 0 We write it in the most significant digit of a binary number.

15 10 : 2 = 7 10

15 10 -14 10 =1 , remainder 1 We write it in the most significant digit of a binary number.

7 10 : 2 = 3 10

7 10 -6 10 =1 , remainder 1 We write it in the most significant digit of a binary number.

3 10 : 2 = 1 10

3 10 -2 10 =1 , remainder 1 We write it in the most significant digit of a binary number.

1 10 : 2 = 0 10 , remainder 1 We write it in the most significant digit of a binary number.

Thus, the required binary number is 11110111 2 .

Converting numbers from decimal to octal

To convert numbers from the decimal number system to octal, use the same “substitution algorithm” as when converting from the decimal number system to binary, only use it as a divisor 8 , base octal number system:

    Divide a decimal number A on 8 . Private Q remember for the next step, and the remainder a write it down as Jr bit of an octal number.

    If private q not equal 0 , take it as the new dividend and repeat the procedure described in step 1. Each new remainder is written to the digits of the octal number in the direction from junior bit to eldest .

    The algorithm continues until, as a result of steps 1 and 2, the quotient is obtained Q=0 and the remainder a less 8 .

For example, you need to convert a decimal number 3336 to octal. In accordance with the above algorithm we obtain:

Thus, the required octal number is 6410 8 .

Originated in ancient Babylon. In India, the system works in the form of positional decimal numbering using zero, among Hindus this system numbers were borrowed by the Arab nation, and the Europeans, in turn, took them 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 the standard spacing 0 - 9 , the next six digits are expressed using the first letters of the Latin alphabet: A, B, C, D, E, F. Convert from hexadecimal to binary and reverse side do the same process for the octal system.

Application of the hexadecimal number system.

The hexadecimal number system is used quite well 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







2024 gtavrl.ru.