How to convert a number from octal to hexadecimal. Converting numbers from hexadecimal to octal


Converting numbers from hexadecimal to octal system

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 Algorithm for converting 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 the following method:

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 most significant 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 proper 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 fraction will not be 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 into binary, ternary and hexadecimal number systems. 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 to record:

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 digits in positional number systems

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 decimal system Calculation 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 progression of numbers in the ternary number system, 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 they used the five-digit number system for a long time.

Computers use binary system because for its implementation they use technical devices with two stable states (no current - 0; current - 1 or not magnetized - 0; magnetized - 1, etc.). Also, the use of the binary number system 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 Performing 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, numbers represented in different number systems must first be reduced to the same 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 system

+ 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 these numbers.

To check, 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

*

Method of converting numbers into different systems calculus

Translation of integers decimal numbers to octal, hexadecimal and binary systems is carried out by successively dividing a decimal number by the base of the system into which it is converted until the quotient of this base is obtained. The number in the new system is written as division remainders, starting with the quotient from the last.

a) Convert the number 19 to the binary number system.

So 19 = 10011 2

b) Convert 181 10 ->”8” number system

Result. 181 10 ->265 8

c) Convert 622 10 - "16" number system

Converting numbers to decimal system carried out by compiling a power series with the base of the system from which the number is translated. The value of the sum is then calculated.

a) Convert 10101101.1012 to the decimal number system

10101101.101 2 = 1 2 7 + 0 2 6 + 1 2 5 + 0 2 4 + 1 2 3 + 1 2 2 + 0 2 1 + 1 2 0 + 1 2 -1 + 0 2 -2 + 1 2 -3 = 173.625 10

b) Convert 703.048 in to the decimal number system

703.048 = 7 82+ 0 81+ 3 80+ 0 8-1+ 4 8-2 = 451,062510

c) Convert B2E.416 to decimal number system

B2E.4 16 = 11 16 2 + 2 16 1 + 14 16 0 + 4 16 -1 = 2862.25 10

For converting an octal or hexadecimal number to binary form it is enough to replace each digit of this number with the corresponding three-digit binary number (triad) (Table 1) or four-digit binary number (tetrad) (Table 1), while discarding unnecessary zeros in the high and low digits.

For change from binary to octal or hexadecimal system proceed as follows: moving from the point to the left and right, they divide the binary number into groups of three (four) digits, supplementing the leftmost and rightmost groups with zeros, if necessary. The triad (tetrad) is then replaced with the corresponding octal (hexadecimal) digit.

Converting from octal to hexadecimal and vice versa carried out through the binary system using triads and tetrads.

Arithmetic operations

Addition

Exactly the same as in the decimal number system

Subtraction

Subtraction of numbers in 2 and 8 SS is performed according to the same rules as in decimal. If the subtrahend is greater than the minuend, the difference is determined between the larger and smaller number, and a minus sign is placed in front of it

Multiplication

The multiplication operation is performed exactly the same as in the decimal number system

Direct code

Used when performing multiplication and division of numbers, and other codes to replace subtraction with addition.

0.011 is a positive number

1.011 is a negative number

By doing multiplication or division operations of two binary fractions, the sign digits are added regardless of the fractional parts

Return code

Used to replace the subtraction operation with addition

For positive numbers: the representation of a proper binary fraction is the same in reverse and forward code

To write a negative proper binary fraction in reverse code, you need to replace zeros with ones and vice versa, and put 1 to the left of the decimal point instead of –0

That is –0.0101=1.1010

Should be considered:

    In case of an overflow, when two digits appear to the left of the decimal point as a result of addition, the leftmost digit is carried over and added to the low-order digit of the fractional part, and the remaining digit to the left of the decimal point determines the sign of the result

    If the number of digits of the fractional part of a negative proper binary fraction is less than the number of digits of the fractional part of another addend, then before converting the negative fraction to return code it is necessary to supplement it on the right with zeros until the digits of the second term are equal

If in the sign digit of the number A the reverse code is 1, then to go to the usual notation you need to replace the units in the fractional part with zeros, and the zeros with ones, and write –0 to the left of the decimal point

Additional code

Just like the inverse, it is used to replace subtraction with addition.

In this case: the image of a positive proper binary fraction is the same in direct, reverse and complement codes.

To convert a negative fraction: It is necessary to replace zeros with ones, and 1s with zeros. Add one to the least significant digit, then put 1 to the left of the decimal point.

Need to remember:

    All digits of the addends, including the digits of the sign bits located to the left of the decimal point, participate in the addition as digits of a single number

    On overflow, when two digits appear to the left of the decimal point as a result of addition, the leftmost digit is discarded, and the remaining digit to the left of the decimal point determines the sign of the result

    the number of digits of the fractional part of another term, then before converting a negative fraction into the reverse code, it is necessary to supplement it on the right with zeros until the digits of the second term are equal

    if the result of addition to the left of the decimal point is 1, then negative number, if 0, then positive (there is no need to translate anything accordingly)







2024 gtavrl.ru.