Methods for converting numbers from one number system to another. Translation of numbers from one number system to another Translation of numbers from a given system to another

To translate numbers from one number system to another, it is necessary to have basic knowledge of number systems and the form of representation of numbers in them.

Quantity s of various digits used in the number system is called the base, or the base of the number system. In general, a positive number X in positional system with base s can be represented as a polynomial:

Where s- base of the number system, - digits allowed in this number system. The sequence forms an integer part X, and the sequence is the fractional part X.

IN computer science the most widely used are binary (BIN - binary), and binary coded number systems: octal (OCT - octal), hexadecimal (HEX - hexadecimal) and binary coded decimal (BCD - binary coded decimal).

In the following, to indicate the number system used, the number will be enclosed in brackets, and the base of the system will be indicated in the index. Number X by reason s will be marked.

Binary number system

The base of the number system is the number 2 ( s= 2) and only two digits are used to write numbers: 0 and 1. To represent any bit of a binary number, it is enough to have a physical element with two clearly different stable states, one of which represents 1 and the other 0.

Before you start translating from any number system to binary, you need to carefully study the example of writing a number in the binary number system:

If you do not need to delve into the theory, but only need to get the result, then use Online calculator Converting integers from decimal to other systems .

Octal and hexadecimal number systems

These number systems are binary-coded, in which the base of the number system is an integer power of two: - for octal and - for hexadecimal.

In the octal number system ( s= 8) 8 digits are used: 0, 1, 2, 3, 4, 5, 6, 7.

Before you start translating from any number system to octal, you need to carefully study the example of writing a number in octal:

In hexadecimal number system ( s= 16) 16 digits are used: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.

An example of writing a number in hexadecimal system:

The widespread use of the octal and hexadecimal number systems is due to two factors.

Firstly, these systems make it possible to replace the notation of a binary number with a more compact representation (the notation of a number in octal and hexadecimal systems will be 3 and 4 times shorter than the binary notation of this number, respectively). Secondly, the mutual conversion of numbers between the binary system, on the one hand, and octal and hexadecimal, on the other, is relatively simple. Indeed, since for an octal number each digit is represented by a group of three binary digits (triads), and for a hexadecimal number - by a group of four binary digits (tetrads), then to convert a binary number, it is enough to combine its digits into groups of 3 or 4 digits, respectively, moving forward from the separating comma to the right and to the left. In this case, if necessary, zeros are added to the left of the integer part and / or to the right of the fractional part, and each such group - a triad or a tetrad - is replaced by an equivalent octal or hexadecimal digit (see table).

If you do not need to delve into the theory, but only need to get the result, then use Online calculator Converting integers from decimal to other systems .

Correspondence between digits in different number systems
DEC BIN OCT HEX BCD
0 0000 0 0 0000
1 0001 1 1 0001
2 0010 2 2 0010
3 0011 3 3 0011
4 0100 4 4 0100
5 0101 5 5 0101
6 0110 6 6 0110
7 0111 7 7 0111
8 1000 10 8 1000
9 1001 11 9 1001
10 1010 12 A 0001 0000
11 1011 13 B 0001 0001
12 1100 14 C 0001 0010
13 1101 15 D 0001 0011
14 1110 16 E 0001 0100
15 1111 17 F 0001 0101

For reverse translation, each OCT or HEX digit is replaced by a triad or tetrad of binary digits, respectively, with insignificant zeros on the left and right discarded.

For the previous examples, it looks like this:

If you do not need to delve into the theory, but only need to get the result, then use Online calculator Converting integers from decimal to other systems .

Binary Decimal Number System

In BCD, the weight of each digit is a power of 10, as in decimal, and each decimal digit is encoded with four binary digits. For the record decimal number in the BCD system, it is enough to replace each decimal digit with the equivalent four-digit binary combination:

Any decimal number can be represented in binary coded decimal notation, but remember that this is not the binary equivalent of a number. This can be seen from the following example:

Converting numbers from one number system to another

Let X- a number in a number system with a base s, which is required to be represented in the system with the base h. It is convenient to distinguish between two cases.

In the first case and, consequently, when passing to the base h you can use the arithmetic of this system. The transformation method consists in representing the number as a polynomial in powers s, as well as in the calculation of this polynomial according to the rules of arithmetic of the number system with base h. So, for example, it is convenient to move from a binary or octal number system to a decimal number system. The described technique is illustrated by the following examples:

.

.

In both cases, arithmetic operations are performed according to the rules of the number system with base 10.

In the second case () it is more convenient to use base arithmetic s. Here it should be borne in mind that the translation of integers and proper fractions is carried out according to different rules. When transferring mixed fractions the integer and fractional parts are translated each according to its own rules, after which the resulting numbers are written separated by commas.

Integer Translation

The rules for translating integers become clear from the general formula for writing a number in an arbitrary positional system. Let the number in the original number system s looks like . It is required to get a record of a number in a number system with a base h:

.

To find the values, we divide this polynomial by h:

.

As you can see, the least significant digit, that is, is equal to the first remainder. The next significant digit is determined by dividing the quotient by h:

.

The rest are also calculated by dividing the quotients until it becomes zero.

To convert an integer from the s-ary number system to the h-ary one, it is necessary to sequentially divide this number and the resulting quotients by h (according to the rules of the number system with base h) until the quotient becomes zero. The highest digit in the record of a number with base h is the last remainder, and the digits following it form the remainders from the previous divisions, written out in the reverse order of their receipt.

From 16 or 8 to 2

Translation octal And hexadecimal numbers into the binary system very simple: it is enough to replace each digit with its equivalent binary triad(three digits) or tetrad(four digits) (see table).
Binary (Base 2) Octal (Base 8) Decimal (Base 10) Hexadecimal (Base 16)
triads tetrads
0 1 0 1 2 3 4 5 6 7 000 001 010 011 100 101 110 111 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 A B C D E F 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

For example:

a) Translate 305.4 8 "2" s.s.

b) Translate 7B2.E 16 "2" s.s.

16A 16 = 1 0110 1010 2 345 8 = 11 100 101 2

From 2 to 16 or 8

For example:

a) Translate 1101111001.1101 2 "8" s.s.

b) Translate 11111111011.100111 2 "16" s.s.

1000101010010101 2 =1000 1010 1001 0101=8A95 16 = 1000 101 010 010 101=105225 8

From 16 to 8 and back

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

For example:

Translate 175.24 8 "16" s.s.

Result: 175.24 8 = 7D.5 16 .

From 10 to any s.s.

For example:

a) Translate 181 10 "8" s.s.

Result: 181 10 = 265 8

b) Translate 622 10 "16" s.s.

Result: 622 10 = 26E 16

Translation of proper fractions
To convert a correct decimal fraction to another system, this fraction must be successively multiplied by the base of the system into which it is being converted. In this case, only fractional parts are multiplied. Fraction in new system is written in the form of whole parts of works, starting from the first.

For example:

Convert 0.3125 10 "8" s.s.

Result: 0.3125 10 = 0.24 8

Comment. A finite decimal fraction in another number system can correspond to an infinite (sometimes periodic) fraction. In this case, the number of characters in the representation of the fraction in the new system is taken depending on the required accuracy.

For example:

Translate 0.65 10 "2" s.s. Accuracy 6 characters.

Result: 0.65 10 0.10(1001) 2

To convert an improper decimal fraction to a number system with a non-decimal base it is necessary to translate the whole part separately and the fractional part separately.

For example:

Translate 23.125 10 "2" s.s.

Thus: 23 10 = 10111 2 ; 0.12510 = 0.0012.
Result: 23.125 10 = 10111.001 2 .

It should be noted that integers remain integers, and proper fractions remain fractions in any number system.

From 2, 8 or 16 to 10

For example:

a)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) Translate 703.04 8 "10" s.s.

703.04 8 = 7 8 2 + 0 8 1 + 3 8 0 + 0 8 -1 + 4 8 -2 = 451.0625 10

c) Translate B2E.4 16 "10" s.s.

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

Scheme for converting numbers from one number system to another


Arithmetic operations in positional number systems

Consider the basic arithmetic operations: addition, subtraction, multiplication and division. The rules for performing these operations in the decimal system are well known - this is addition, subtraction, multiplication by a column and division by an angle. These rules apply to all other positional number systems. Only tables of addition and multiplication should be used specific for each system.

Addition

When adding, the numbers are summed up by digits, and if an excess occurs, then it is transferred to the left

When adding binary numbers in each digit, the digits of the terms and the transfer from the adjacent low-order digit, if any, are added. It should be taken into account that 1 + 1 gives a zero in a given bit and a unit of transfer to the next one.

For example:

Perform binary addition:
a) X=1101, Y=101;

Result 1101+101=10010.

b) X=1101, Y=101, Z=111;

Result 1101+101+111=11001.

Addition table in the 8th number system

2+2=4 3+2=5 4+2=6 5+2=7 6+2=10 7+2=11
2+3=5 3+3=6 4+3=7 5+3=10 6+3=11 7+3=12
2+4=6 3+4=7 4+4=10 5+4=11 6+4=12 7+4=13
2+5=7 3+5=10 4+5=11 5+5=12 6+5=13 7+5=14
2+6=10 3+6=11 4+6=12 5+6=13 6+6=14 7+6=15
2+7=11 3+7=12 4+7=13 5+7=14 6+7=15 7+7=16

Addition table in the 16th number 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

The calculator allows you to convert whole and fractional numbers from one number system to another. The base of the number system cannot be less than 2 and more than 36 (10 digits and 26 Latin letters, after all). Numbers must not exceed 30 characters. For input fractional numbers use symbol. or, . To convert a number from one system to another, enter the original number in the first field, the base of the original number system in the second, and the base of the number system to which you want to convert the number in the third field, then click the "Get Entry" button.

original number recorded in 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 -th number system.

I want to get a record of a number in 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 -th number system.

Get an entry

Translations completed: 3336969

It may also be of interest:

  • Truth table calculator. SDNF. SKNF. Zhegalkin polynomial

Number systems

Number systems are divided into two types: positional And not positional. We use the Arabic system, it is positional, and there is also the Roman one - it is just not positional. In positional systems, the position of a digit in a number uniquely determines the value of that number. This is easy to understand by looking at the example of some number.

Example 1. Let's take the number 5921 in the decimal number system. We number the number from right to left starting from zero:

The number 5921 can be written in the following form: 5921 = 5000+900+20+1 = 5 10 3 +9 10 2 +2 10 1 +1 10 0 . The number 10 is a characteristic that defines the number system. The values ​​of the position of the given number are taken as degrees.

Example 2. Consider the real decimal number 1234.567. We number it starting from the zero position of the number from the decimal point to the left and to the right:

The number 1234.567 can be written as follows: 1234.567 = 1000+200+30+4+0.5+0.06+0.007 = 1 10 3 +2 10 2 +3 10 1 +4 10 0 +5 10 -1 + 6 10 -2 +7 10 -3 .

Converting numbers from one number system to another

Most in a simple way transferring a number from one number system to another is the translation of the number first into the decimal number system, and then, the result obtained into the required number system.

Converting numbers from any number system to decimal number system

To convert a number from any number system to decimal, it is enough to number its digits, starting from zero (the digit to the left of the decimal point) similarly to examples 1 or 2. Let's find the sum of the products of the digits of the number by the base of the number system to the power of the position of this digit:

1. Convert number 1001101.1101 2 to decimal number system.
Solution: 10011.1101 2 = 1 2 4 +0 2 3 +0 2 2 +1 2 1 +1 2 0 +1 2 -1 +1 2 -2 +0 2 -3 +1 2 - 4 = 16+2+1+0.5+0.25+0.0625 = 19.8125 10
Answer: 10011.1101 2 = 19.8125 10

2. Convert number E8F.2D 16 to decimal number system.
Solution: E8F.2D 16 = 14 16 2 +8 16 1 +15 16 0 +2 16 -1 +13 16 -2 = 3584+128+15+0.125+0.05078125 = 3727.17578125 10
Answer: E8F.2D 16 = 3727.17578125 10

Converting numbers from a decimal number system to another number system

To convert numbers from a decimal number system to another number system, the integer and fractional parts of the number must be translated separately.

Converting the integer part of a number from a decimal number system to another number system

The integer part is translated from the decimal number system to another number system by successively dividing the integer part of the number by the base of the number system until an integer remainder is obtained, less than the base of the number system. The result of the transfer will be a record from the remains, starting with the last one.

3. Convert number 273 10 to octal number system.
Solution: 273 / 8 = 34 and remainder 1, 34 / 8 = 4 and remainder 2, 4 is less than 8, so the calculation is complete. The record from the remnants will look like this: 421
Examination: 4 8 2 +2 8 1 +1 8 0 = 256+16+1 = 273 = 273 , the result is the same. So the translation is correct.
Answer: 273 10 = 421 8

Let's consider the translation of correct decimal fractions into various number systems.

Converting the fractional part of a number from a decimal number system to another number system

Recall the correct decimal called real number with zero whole part . To translate such a number into a number system with base N, you need to consistently multiply the number by N until the fractional part is zeroed or the required number of digits is obtained. If during multiplication a number with an integer part other than zero is obtained, then the integer part is not taken into account further, since it is sequentially entered into the result.

4. Convert number 0.125 10 to binary number system.
Solution: 0.125 2 = 0.25 (0 is the integer part, which will be the first digit of the result), 0.25 2 = 0.5 (0 is the second digit of the result), 0.5 2 = 1.0 (1 is the third digit of the result, and since the fractional part is zero , the translation is complete).
Answer: 0.125 10 = 0.001 2

Consider ways to translate numbers from one number system to another.

a) Converting a binary number to decimal.

It is necessary to add twos in powers corresponding to the positions where ones are in binary. For example:

Take the number 20. In binary, it looks like this: 10100.

So (counting from left to right, counting from 4 to 0; a number to the power of zero is always equal to one)

10100 = 1*2 4 + 0*2 3 + 1*2 2 + 0*2 1 + 0*2 0 = 20

16+0+4+0+0 = 20.

b) Converting a decimal number to binary.

It is necessary to divide it by two, writing the remainder from right to left:

20/2 = 10, remainder 0

10/2=5, remainder 0

5/2=2, remainder 1

2/2=1, remainder 0

1/2=0, remainder 1

As a result, we get: 10100 = 20

c) Converting a hexadecimal number to decimal.

In the hexadecimal system, the position number of the digit in the number corresponds to the power to which the number 16 must be raised:

8A=8*16+10(0A)=138

Finally, we present an algorithm for converting to and from a binary system, proposed by L. Radyuk.

Let A(cd) be an integer decimal number. We write it as the sum of powers of base 2 with binary coefficients. In his record in expanded form will be absent negative powers bases (numbers 2):

A(cd) = a(n-1) * 2^(n-1) + a(n-2) * 2^(n-2) + … + a(1) * 2^1 + a(0) *2^0.

At the first step, we divide the number A (tsd) by the base of the binary system, that is, by 2. The quotient of division will be equal to:

a(n-1) * 2^(n-2) + a(n-2) * 2^(n-3) + ... + a(1) and the remainder is a(0).

At the second step, the integer quotient is again divided by 2, the remainder of the division will now be equal to a (1).

If we continue this division process, then after the nth step we get a sequence of residues:

a(0), a(1),…, a(n-1).

It is easy to see that their sequence coincides with the reverse sequence of digits of a binary integer written in folded form:

A(2) = a(n-1)…a(1)a(0).

Thus, it is enough to write the remainders in reverse order to get the desired binary number.

Then the algorithm itself will be as follows:

1. Consistently perform the division of the original integer decimal number and the resulting integer quotients by the base of the system (by 2) until a quotient is obtained that is less than the divisor, that is, less than 2.

2. Write down the resulting balances in reverse order, and add the last quotient on the left.

To convert numbers from octal and hexadecimal to binary, you need to convert the digits of the number into groups of binary digits. To convert from the octal system to binary, each digit of the number must be converted into a group of three binary digits a triad, and when converting a hexadecimal number into a group of four digits, a tetrad.

CONCLUSION

Summarizing the results of the work, the following conclusions can be drawn.

The positional number system consists in using a limited number of digits, but the position of each digit in the number provides the significance (weight) of this digit. The position of the digit in the number mathematical language called a rank.

The base of a positional number system is the number of different characters or symbols (digits) used to display numbers in a given system.

In order to make binary numbers, which differ in a rather significant length, easier to perceive and display, they are compressed into octal and hexadecimal number systems.

IN computer technology all types of information are encoded only by numbers or, more precisely, by numbers that are represented in the binary system, the way of representing any numbers using two characters (numbers) according to the positional principle.

Passing the exam and not only ...

It is strange that in schools in computer science classes they usually show students the most complex and inconvenient way to translate numbers from one system to another. This method consists in sequentially dividing the original number by the base and collecting the remainder of the division in reverse order.

For example, you need to convert the number 810 10 to the binary system:

The result is written in reverse order from bottom to top. It turns out 81010 = 11001010102

If you need to convert to a binary system, quite big numbers, then the division staircase takes on the size of a multi-storey building. And how can you collect all the ones with zeros and not miss a single one?

The USE program in computer science includes several tasks related to the translation of numbers from one system to another. As a rule, this is a conversion between 8- and 16-ary 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 it 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 these numbers, it is not difficult to get the rest in your mind from those that you remember.

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

Missing values ​​are also easy to calculate by adding 1 to the known values.

Integer Translation

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 nearest power of two to 810, not exceeding it. This is 29 = 512.
  2. Subtract 512 from 810, we get 298.
  3. Repeat steps 1 and 2 until either 1 or 0 remains.
  4. We got it like this: 810 \u003d 512 + 256 + 32 + 8 + 2 \u003d 2 9 + 2 8 + 2 5 + 2 3 + 2 1.
Then there are two ways, 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 is 1000. That is, the degree of the base of the number system is 1 (one), and after it there are as many zeros as the degree.

Method 1: Arrange 1 according to the digits that the indicators of the terms turned out to be. In our example, these are 9, 8, 5, 3 and 1. The rest of the places will be zeros. So, we got the binary representation of the number 810 10 = 1100101010 2 . Units are 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 =

And now let's put these steps together, like a fan is folded: 1100101010.

That's all. Along the way, the problem “how many units are in the binary representation of the number 810?” is also simply solved.

The answer is as many as the terms (powers of two) in this representation. The 810 has 5.

Now the example is simpler.

Let's translate the number 63 into the 5-ary number system. The nearest power of 5 to 63 is 25 (square 5). Cube (125) will already be a lot. That is, 63 lies between the square of 5 and the cube. Then we 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 16-decimal systems. Since their base is a power of two, the translation is done automatically, simply by replacing the digits with their binary representation. For the octal system, each digit is replaced by three binary digits, and for the hexadecimal system by four. In this case, all leading zeros are required, except for the most significant digit.

Let's translate the number 547 8 into the binary system.

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 translate the number 7368 into the hexadecimal system. First, write the numbers in threes, and then divide them into fours from the end: 736 8 \u003d 111 011 110 \u003d 1 1101 1110 \u003d 1DE 16. Let's convert the number C25 16 to the 8-ary system. First, we write the numbers in fours, and then we divide them into threes from the end: C25 16 \u003d 1100 0010 0101 \u003d 110 000 100 101 \u003d 6045 8. Now consider converting back to decimal. It is not difficult, the main thing is not to make mistakes in the calculations. We decompose the number into a polynomial with base degrees and coefficients at them. Then we multiply and add everything. E68 16 = 14 * 16 2 + 6 * 16 + 8 = 3688. 732 8 \u003d 7 * 8 2 + 3 * 8 + 2 \u003d 474 .

Translation of negative numbers

Here you need to take into account that the number will be presented in an additional code. To translate a number into an additional code, you need to know the final size of the number, that is, what we want to write it into - into a byte, into two bytes, into four. The most significant digit of the number means the sign. If there is 0, then the number is positive, if 1, then negative. On the left, the number is padded with a sign bit. We do not consider unsigned numbers, they are always positive, and the most significant digit in them is used as informational.

For translate negative number In the binary additional code, you need to convert a positive number to the binary system, then change zeros to ones and ones to zeros. Then add 1 to the result.

So, let's translate the number -79 into the binary system. The number will take us one byte.

We translate 79 into binary system, 79 = 1001111. We add zeros to the left to the byte size, 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 USE question “how many units are in the binary representation of the number -79?”. The answer is 4.

Adding 1 to the inverse of the number eliminates the difference between the representations +0 = 00000000 and -0 = 11111111. In two's complement code, they will be written the same 00000000.

Translation of fractional numbers

Fractional numbers are translated in the reverse way to the division of integers by the base, which we considered at the very beginning. That is, by successive multiplication by a new base with the collection of whole parts. The integer parts obtained by 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, then glued together.

Let's translate the number 0.6752 into 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 would be 101.101011 .