Conversion from octal to hexadecimal example. Converting numbers from hexadecimal to octal

Converting numbers from hexadecimal to octal

To convert a number from hexadecimal to octal:

1. This number must be represented in the binary system.

2. Then divide the resulting number in the binary system into triads and convert it to the octal system.

For example:

1.7 Conversion algorithm proper fractions from any number system to the decimal system

Converting a number to the decimal system WITH, both integer and fractional, written in the q-ary number system is carried out using the decomposition of the number according to the basis according to formula 1 (see Section 1.2).

However, to convert proper fractions you can use next way:

1. The least significant digit of the fraction 0.A q divide by base q. To the resulting quotient add the digit of the next (higher) digit of the number 0,A q .

2. The amount received should again be divided by q and again add the digit of the next digit of the number.

3. Do this until the highest digit of the fraction is added.

4. Divide the resulting amount again by q and add a comma and zero integers to the result.

For example: Let's convert fractions to the decimal number system:

a). 0,1101 2 b). 0,356 8
1/2 + 0 = 0,5 6/8+5 = 5,75
0,5/2 + 1 = 1,25 5,75/8 + 3 = 3,71875
1,25/2 + 1 = 1,625 3,71875/8 = 0,46484375
1,625/2 = 0,8125
Answer:0.1101 2 = 0,8125 10 Answer: 0.356 8 = 0,46484375 10

1.8 Algorithm for converting regular decimal fractions to any other number system

1. Multiply given number on a new basis R.

2. The integer part of the resulting product is the highest digit of the desired fraction.

3. The fractional part of the resulting product is again multiplied by R and the integer part of the result is considered the next digit of the desired fraction.

4. Continue operations until the fractional part is equal to zero or the required accuracy will not be achieved.

5. The maximum absolute error in converting the number D is equal to q -(k +1) /2, where k is the number of decimal places.

For example: Let's convert the decimal fraction 0.375 to binary, ternary and hexadecimal system Reckoning. Perform translation accurate to the third digit.

For example: Let's convert the number 0.36 10 into binary, octal and hexadecimal systems:

It is convenient to use this form for recording:

Transfer to Transfer to Transfer to

binary s/c. octal s/c. hexadecimal

0, x 36 0, x 36 0, x 36
x 72 x 88 x 76
x 44 x04 x 16
x 88 x 32 x 56
x 76 x 46 x 96
x 52 x 68 x 36

0.36 10 = 0.010111 2 with maximum absolute error (2 -7)/2=2 -8

0.36 10 = 0.270235 8 with maximum absolute error
(8 -7)/2=2 -22

0.36 10 = 0.5C28F5 16 with maximum absolute error
(16 -7)/2=2 -29

For numbers that have both integer and fractional parts, conversion from the decimal number system to another is carried out separately for the integer and fractional parts according to the rules specified above.

1.9 Promotion of figures in positional systems dead reckoning

In every number system, digits are ordered according to their meanings: 1 is greater than 0, 2 is greater than 1, etc.

Any positional number system is based on the same principles of construction and transition from minor to senior digits.

Let's consider the advancement of digits in the positional number system.

Promoting figures they call replacing it with the next largest one (by adding one).

In the decimal number system, the progression of digits is as follows:

Again we reached the number 9, so there is a transition to a higher digit, but in the position of the 1st digit there is already the number 1, so the number 1 of the first digit is also promoted, i.e. 1+1=2 (two tens). So we advance the numbers until the highest digit in the number system appears in the first digit (in our example it is 9); now the transition is carried out to the next digit.

Let us now consider the advancement of numbers in ternary system notation, i.e. q=3 (digits 0, 1, 2 are used) and the most significant digit is 2.

0+1 1+1
2+1 10+1 11+1
12+1 20+1 21+1
22+1 100+1 101+1
102+1 110+1 111+1
etc.

In life, we use the decimal number system, probably because since ancient times we have been counting on our fingers, and, as you know, there are ten fingers on our hands and feet. Although in China for a long time They used the quinary number system.

Computers use the binary system because they use technical devices with two stable states (no current - 0; current - 1 or not magnetized - 0; magnetized - 1, etc.). Also application binary system calculus allows you to use the apparatus of Boolean algebra (see section 2) to perform logical transformations of information. Binary arithmetic is much simpler than decimal arithmetic, but its disadvantage is the rapid increase in the number of digits required to write numbers.

For example: Let's advance the numbers in the binary number system, where q=2, (digits 0, 1 are used) most significant digit 1:

0, 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111, etc.

As can be seen from the example, the third number in the series has already moved one digit higher, i.e. took the place (if it were a decimal) of “tens”. The fifth number is the place of “hundreds”, the ninth number is the place of “thousands”, etc. In the decimal system, the transition to another digit is much slower. The binary system is convenient for computers, but inconvenient for humans due to its bulkiness and unusual recording.



Converting numbers from decimal to binary and vice versa is performed by computer programs. However, in order to work and use a computer professionally, you must understand the word machine. Octal and hexadecimal systems have been developed for this purpose.

In order to easily operate with these systems, you need to learn how to convert numbers from one system to another and vice versa, as well as perform simple operations on numbers - addition, subtraction, multiplication, division.

1.10 Execution arithmetic operations in positional number systems

The rules for performing basic arithmetic operations in the decimal system are well known - addition, subtraction, multiplication by column and division by angle. These rules apply to all other positional number systems. Only the addition and multiplication tables for each system are different.

Arithmetic operations in positional number systems are performed according to general rules. You just need to remember that the transfer to the next digit when adding and the borrowing from the highest digit when subtracting are determined by the value of the base of the number system.

When performing arithmetic operations, the numbers represented in different systems Numbers must first be reduced to one base.

Addition

Addition tables are easy to create using the counting rule. When adding, the digits are summed by digits, and if an excess occurs, it is transferred to the left into the next digit.

Table 1.4

Addition in binary system:

+

Table 1.5

Addition in octal system

+

Table 1.6

Addition in hexadecimal

+ A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A A B C D E F
B B C D E F 1A
C C D E F 1A 1B
D D E F 1A 1B 1C
E E F 1A 1B 1C 1D
F F 1A 1B 1C 1D 1E

For example:


a) Add the numbers 1111 2 and 110 2:

c) Add the numbers F 16 and 6 16:

b) Add the numbers 17 8 and 6 8:


d) Add two numbers: 17 8 and 17 16.

Let's convert the number 17 16 to base 8 using the binary system

17 16 =10111 2 =27 8. Let's perform addition in octal system:

d ) Let's add 2 numbers. 10000111 2 + 89 10

Method 1: Convert the number 10000111 2 to decimal notation.

10000111 2 = 1*2 7 + 1*2 2 + 1*2 1 + 1*2 0 =128 + 4 + 2 + 1 = 135 10

135 10 + 89 10 = 224 10

Method 2: Convert the number 89 10 to the binary system in any way.

89 10 = 1011001 2

Let's add up these numbers.

To check, let's convert this number to decimal notation.

11100000 2 = 1*2 7 + 1*2 6 +1*2 5 = 128+64+32 = 224 10


Subtraction

Let's find the difference between the numbers:

a) 655 8 and 367 8 b) F5 16 and 6 16

Multiplication

Table 1.7

Multiplication in binary system:

*

Table 1.8

Multiplication in octal system

*

The result has already been received!

Number systems

There are positional and non-positional number systems. The Arabic number system that we use in Everyday life, is positional, but Roman is not. In positional number systems, the position of a number uniquely determines the magnitude of the number. Let's consider this using the example of the number 6372 in the decimal number system. Let's number this number from right to left starting from zero:

Then the number 6372 can be represented as follows:

6372=6000+300+70+2 =6·10 3 +3·10 2 +7·10 1 +2·10 0 .

The number 10 defines the number system (in in this case this is 10). The values ​​of the position of a given number are taken as powers.

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

Then the number 1287.923 can be represented as:

1287.923 =1000+200+80 +7+0.9+0.02+0.003 = 1·10 3 +2·10 2 +8·10 1 +7·10 0 +9·10 -1 +2·10 -2 +3· 10 -3.

IN general case the formula can be represented as follows:

C n s n +C n-1 · s n-1 +...+C 1 · s 1 +C 0 ·s 0 +D -1 ·s -1 +D -2 ·s -2 +...+D -k ·s -k

where C n is an integer in position n, D -k - fractional number in position (-k), s- number system.

A few words about number systems. A number in the decimal number system consists of many digits (0,1,2,3,4,5,6,7,8,9), in the octal number system it consists of many digits (0,1, 2,3,4,5,6,7), in the binary number system - from a set of digits (0,1), in the hexadecimal number system - from a set of digits (0,1,2,3,4,5,6, 7,8,9,A,B,C,D,E,F), where A,B,C,D,E,F correspond to the numbers 10,11,12,13,14,15. In the table Tab.1 numbers are presented in different number systems.

Table 1
Notation
10 2 8 16
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F

Converting numbers from one number system to another

To convert numbers from one number system to another, the easiest way is to first convert the number to the decimal number system, and then convert from the decimal number system to the required number system.

Converting numbers from any number system to the decimal number system

Using formula (1), you can convert numbers from any number system to the decimal number system.

Example 1. Convert the number 1011101.001 from binary number system (SS) to decimal SS. Solution:

1 ·2 6 +0 ·2 5 + 1 ·2 4 + 1 ·2 3 + 1 ·2 2 + 0 ·2 1 + 1 ·2 0 + 0 ·2 -1 + 0 ·2 -2 + 1 ·2 -3 =64+16+8+4+1+1/8=93.125

Example2. Convert the number 1011101.001 from octal number system (SS) to decimal SS. Solution:

Example 3 . Convert the number AB572.CDF from hexadecimal number system to decimal SS. Solution:

Here A-replaced by 10, B- at 11, C- at 12, F- by 15.

Converting numbers from the decimal number system to another number system

To convert numbers from the decimal number system to another number system, you need to separately convert the whole part of the number and fractional part numbers.

The integer part of a number is converted from decimal SS to another number system by sequentially dividing the integer part of the number by the base of the number system (for binary SS - by 2, for 8-ary SS - by 8, for 16-ary SS - by 16, etc. ) until a whole residue is obtained, less than the base CC.

Example 4 . Let's convert the number 159 from decimal SS to binary SS:

159 2
158 79 2
1 78 39 2
1 38 19 2
1 18 9 2
1 8 4 2
1 4 2 2
0 2 1
0

As can be seen from Fig. 1, the number 159 when divided by 2 gives the quotient 79 and remainder 1. Further, the number 79 when divided by 2 gives the quotient 39 and remainder 1, etc. As a result, constructing a number from division remainders (from right to left), we obtain a number in binary SS: 10011111 . Therefore we can write:

159 10 =10011111 2 .

Example 5 . Let's convert the number 615 from decimal SS to octal SS.

615 8
608 76 8
7 72 9 8
4 8 1
1

When converting a number from a decimal SS to an octal SS, you need to sequentially divide the number by 8 until you get an integer remainder less than 8. As a result, constructing a number from division remainders (from right to left) we get a number in octal SS: 1147 (See Fig. 2). Therefore we can write:

615 10 =1147 8 .

Example 6 . Let's convert the number 19673 from the decimal number system to hexadecimal SS.

19673 16
19664 1229 16
9 1216 76 16
13 64 4
12

As can be seen from Figure 3, by successively dividing the number 19673 by 16, the remainders are 4, 12, 13, 9. In the hexadecimal number system, the number 12 corresponds to C, the number 13 - D. Therefore, our hexadecimal number- this is 4CD9.

To convert proper decimal fractions ( real number from scratch whole part) into a number system with base s, it is necessary to sequentially multiply this number by s until the fractional part is pure zero, or we obtain the required number of digits. If, during multiplication, a number with an integer part other than zero is obtained, then this integer part is not taken into account (they are sequentially included in the result).

Let's look at the above with examples.

Example 7 . Let's convert the number 0.214 from the decimal number system to binary SS.

0.214
x 2
0 0.428
x 2
0 0.856
x 2
1 0.712
x 2
1 0.424
x 2
0 0.848
x 2
1 0.696
x 2
1 0.392

As can be seen from Fig. 4, the number 0.214 is sequentially multiplied by 2. If the result of multiplication is a number with an integer part other than zero, then the integer part is written separately (to the left of the number), and the number is written with a zero integer part. If the multiplication results in a number with a zero integer part, then a zero is written to the left of it. The multiplication process continues until the fractional part reaches a pure zero or we obtain the required number of digits. Writing bold numbers (Fig. 4) from top to bottom we get the required number in the binary number system: 0. 0011011 .

Therefore we can write:

0.214 10 =0.0011011 2 .

Example 8 . Let's convert the number 0.125 from the decimal number system to binary SS.

0.125
x 2
0 0.25
x 2
0 0.5
x 2
1 0.0

To convert the number 0.125 from decimal SS to binary, this number is sequentially multiplied by 2. In the third stage, the result is 0. Consequently, the following result is obtained:

0.125 10 =0.001 2 .

Example 9 . Let's convert the number 0.214 from the decimal number system to hexadecimal SS.

0.214
x 16
3 0.424
x 16
6 0.784
x 16
12 0.544
x 16
8 0.704
x 16
11 0.264
x 16
4 0.224

Following examples 4 and 5, we get the numbers 3, 6, 12, 8, 11, 4. But in hexadecimal SS, the numbers 12 and 11 correspond to the numbers C and B. Therefore, we have:

0.214 10 =0.36C8B4 16 .

Example 10 . Let's convert the number 0.512 from the decimal number system to octal SS.

0.512
x 8
4 0.096
x 8
0 0.768
x 8
6 0.144
x 8
1 0.152
x 8
1 0.216
x 8
1 0.728

Got:

0.512 10 =0.406111 8 .

Example 11 . Let's convert the number 159.125 from the decimal number system to binary SS. To do this, we translate separately the integer part of the number (Example 4) and the fractional part of the number (Example 8). Further combining these results we get:

159.125 10 =10011111.001 2 .

Example 12 . Let's convert the number 19673.214 from the decimal number system to hexadecimal SS. To do this, we translate separately the integer part of the number (Example 6) and the fractional part of the number (Example 9). Further, combining these results we obtain.

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

Translation of integers 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 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 octal (hexadecimal), you need to split the decimal point to the right and left binary number 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

Conversion of numbers from 2, 8 and 16 to the decimal system is carried out 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 its serial number in the number being converted. In this case, the numbers are numbered to the left of the decimal point (the first number is numbered 0) in increasing order, and in right side 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.

  1. 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
    • From the decimal number system:
    • divide the number by the base of the number system being translated;
  2. find the remainder when dividing an integer part of a number;
    • write down all remainders from division in reverse order;
    • 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
Number system correspondence table:Table for conversion to hexadecimal number system
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

Binary SS