Convert a number to hexadecimal number system online. Number systems

  • 21.10.2019

Hello, site visitor! We continue to study the IP network layer protocol, and to be more precise, its version IPv4. At first glance the topic binary numbers and binary number system has nothing to do with the IP protocol, but if we remember that computers work with zeros and ones, then it turns out that the binary system and its understanding is the basis of the fundamentals, we need learn to convert numbers from binary to decimal and vice versa: decimal to binary. This will help us better understand the IP protocol, as well as the principle of operation of variable-length network masks. Let's get started!

If the topic of computer networks is interesting to you, you can read other course recordings.

4.4.1 Introduction

Before we begin, it’s worth explaining why a network engineer needs this topic. Although you could be convinced of its necessity when we spoke, you can say that there are IP calculators that greatly facilitate the task of allocating IP addresses, calculating the necessary subnet/network masks and determining the network number and host number in the IP address. That’s right, but the IP calculator is not always at hand, this is the reason number one. Reason number two is that in the Cisco exams they won't give you an IP calculator and that's it. you will have to do the conversion of IP addresses from decimal to binary on a piece of paper, and there are not so few questions where this is required in the exam/exams for obtaining the CCNA certificate, it would be a shame if the exam was failed because of such a trifle. And finally, understanding the binary number system leads to a better understanding of the principle of operation.

In general, a network engineer is not required to be able to convert numbers from binary to decimal and vice versa in his head. Moreover, rarely anyone knows how to do this mentally; teachers of various courses on computer networks mainly fall into this category, since they constantly encounter this every day. But with a piece of paper and a pen, you should learn how to translate.

4.4.2 Decimal digits and numbers, digits in numbers

Let's start simple and talk about binary digits and numbers, you know that numbers and numbers are two different things. A number is a special symbol for designation, and a number is an abstract notation for quantity. For example, to write down that we have five fingers on our hand, we can use Roman and Arabic numerals: V and 5. In this case, five is both a number and a digit. And, for example, to write the number 20 we use two digits: 2 and 0.

In total, in the decimal number system we have ten digits or ten symbols (0,1,2,3,4,5,6,7,8,9), by combining which we can write different numbers. What principle are we guided by when using the decimal number system? Yes, everything is very simple, we raise ten to one power or another, for example, let’s take the number 321. How can it be written differently, like this: 3*10 2 +2*10 1 +1*10 0 . Thus, it turns out that the number 321 represents three digits:

  1. The number 3 means the most significant place or in this case it is the hundreds place, otherwise their number.
  2. The number 2 is in the tens place, we have two tens.
  3. The number one refers to the least significant digit.

That is, in this entry a two is not just a two, but two tens or two times ten. And three is not just three, but three times a hundred. The following dependence is obtained: the unit of each next digit is ten times greater than the unit of the previous one, because what 300 is is three times a hundred. A digression regarding the decimal number system was necessary to make it easier to understand the binary system.

4.4.3 Binary digits and numbers, as well as their recording

There are only two digits in the binary number system: 0 and 1. Therefore, writing a number in the binary system is often much larger than in the decimal system. With the exception of the numbers 0 and 1, zero in the binary number system is equal to zero in the decimal number system, and the same is true for one. Sometimes, in order not to confuse which number system the number is written in, sub-indices are used: 267 10, 10100 12, 4712 8. The number in the sub-index indicates the number system.

The symbols 0b and &(ampersand) can be used to write binary numbers: 0b10111, &111. If in the decimal number system, to pronounce the number 245 we use this construction: two hundred and forty-five, then in the binary number system, to name the number, we need to pronounce a digit from each digit, for example, the number 1100 in the binary number system should not be pronounced as a thousand one hundred, but like one, one, zero, zero. Let's look at writing the numbers from 0 to 10 in the binary number system:

I think the logic should be clear by now. If in the decimal number system for each digit we had ten options available (from 0 to 9 inclusive), then in the binary number system in each of the digits of a binary number we have only two options: 0 or 1.

To work with IP addresses and subnet masks, we only need natural numbers in the binary number system, although the binary system allows us to write fractional and negative numbers, but we don’t need this.

4.4.4 Converting numbers from decimal to binary

Let's take a better look at this how to convert a number from decimal to binary. And here everything is actually very, very simple, although it’s difficult to explain in words, so I’ll give it right away example of converting numbers from decimal to binary. Let's take the number 61, to convert to the binary system, we need to divide this number by two and see what is the remainder of the division. And the result of division is again divided by two. In this case, 61 is the dividend, we will always have two as a divisor, and we divide the quotient (the result of division) by two again, continue dividing until the quotient contains 1, this last unit will be the leftmost digit . The picture below demonstrates this.

Please note that the number 61 is not 101111, but 111101, that is, we write the result from the end. In the latter particular, there is no sense in dividing one by two, since in this case integer division is used, and with this approach it turns out as in Figure 4.4.2.

This is not the fastest way to convert a number from binary to decimal.. We have several accelerators. For example, the number 7 in binary is written as 111, the number 3 as 11, and the number 255 as 11111111. All these cases are incredibly simple. The fact is that the numbers 8, 4, and 256 are powers of two, and the numbers 7, 3, and 255 are one less than these numbers. So, for numbers that are one less than a number equal to a power of two, a simple rule applies: in the binary system, such a decimal number is written as a number of units equal to a power of two. So, for example, the number 256 is two to the eighth power, therefore, 255 is written as 11111111, and the number 8 is two to the third power, and this tells us that 7 in the binary number system will be written as 111. Well, understand, how to write 256, 4 and 8 in the binary number system is also not difficult, just add one: 256 = 11111111 + 1 = 100000000; 8 = 111 + 1 = 1000; 4 = 11 + 1 = 100.
You can check any of your results on a calculator and it’s better to do so at first.

As you can see, we have not yet forgotten how to divide. And now we can move on.

4.4.5 Converting numbers from binary to decimal

Converting numbers from binary is much easier than converting from decimal to binary. As an example of translation, we will use the number 11110. Pay attention to the table below, it shows the power to which you need to raise two in order to eventually get a decimal number.

To get a decimal number from this binary number, you need to multiply each number in the digit by two to the power, and then add the results of the multiplication, it’s easier to show:

1*2 4 +1*2 3 +1*2 2 +1*2 1 +0*2 0 = 16+8+4+2+0=30

Let's open the calculator and make sure that 30 in the decimal number system is 11110 in binary.

We see that everything was done correctly. From the example it is clear that Converting a number from binary to decimal is much easier than converting it back. To work with confidence you just need to remember powers of two up to 2 8. For clarity, I will provide a table.

We don’t need more, since the maximum possible number that can be written in one byte (8 bits or eight binary values) is 255, that is, in each octet of the IP address or IPv4 subnet mask, the maximum possible value is 255. There are fields , in which there are values ​​greater than 255, but we do not need to calculate them.

4.4.6 Addition, subtraction, multiplication of binary numbers and other operations with binary numbers

Let's now look at operations that can be performed on binary numbers. Let's start with simple arithmetic operations and then move on to Boolean algebra operations.

Adding binary numbers

Adding binary numbers is not that difficult: 1+0 =1; 1+1=0 (I’ll give an explanation later); 0+0=0. These were simple examples where only one digit was used, let's look at examples where the number of digits is more than one.
101+1101 in the decimal system is 5 + 13 = 18. Let's count in a column.

The result is highlighted in orange, the calculator says that we calculated correctly, you can check it. Now let's see why this happened, because at first I wrote that 1+1=0, but this is for the case when we have only one digit, for cases when there are more than one digits, 1+1=10 (or two in decimal), which is logical.

Then look what happens, we perform additions by digits from right to left:

1. 1+1=10, write zero, and one goes to the next digit.

2. In the next digit we get 0+0+1=1 (this unit came to us from the result of addition in step 1).

4. Here we have a unit only in the second number, but it has also been transferred here, so 0+1+1 = 10.

5. Glue everything together: 10|0|1|0.

If you’re lazy in a column, then let’s count like this: 101011+11011 or 43 + 27 = 70. What can we do here, but let’s look, because no one forbids us to make transformations, and changing the places of the terms does not change the sum, for the binary number system this rule is also relevant.

  1. 101011 = 101000 + 11 = 101000 + 10 + 1 = 100000 + 1000 + 10 + 1.
  2. 11011 = 11000 + 10 + 1 = 10000 + 1000 + 10 + 1.
  3. 100000 + 10000 + (1000 +1000) + (10+10) + (1+1).
  4. 100000 + (10000 + 10000) + 100 + 10.
  5. 100000 + 100000 +110
  6. 1000000 + 110.
  7. 1000110.

You can check with a calculator, 1000110 in binary is 70 in decimal.

Subtracting Binary Numbers

Immediately an example for subtracting single-digit numbers in the binary number system, we didn’t talk about negative numbers, so we don’t take 0-1 into account: 1 – 0 = 1; 0 – 0 = 0; 1 – 1 = 0. If there is more than one digit, then everything is also simple, you don’t even need any columns or tricks: 110111 – 1000, this is the same as 55 – 8. As a result, we get 101111. And the heart stopped beating , where does the unit in the third digit come from (numbering from left to right and starting from zero)? It's simple! In the second digit of the number 110111 there is 0, and in the first digit there is 1 (if we assume that the numbering of digits starts from 0 and goes from left to right), but the unit of the fourth digit is obtained by adding two units of the third digit (you get a kind of virtual two) and from this For twos, we subtract one, which is in the zero digit of the number 1000, and 2 - 1 = 1, and 1 is a valid digit in the binary number system.

Multiplying binary numbers

It remains for us to consider the multiplication of binary numbers, which is implemented by shifting one bit to the left. But first, let's look at the results of single-digit multiplication: 1*1 = 1; 1*0=0 0*0=0. Actually, everything is simple, now let's look at something more complex. Let's take the numbers 101001 (41) and 1100 (12). We will multiply by column.

If it is not clear from the table how this happened, then I will try to explain in words:

  1. It is convenient to multiply binary numbers in a column, so we write out the second factor under the first; if the numbers have different numbers of digits, it will be more convenient if the larger number is on top.
  2. The next step is to multiply all the digits of the first number by the lowest digit of the second number. We write the result of the multiplication below; we need to write it so that under each corresponding digit the result of the multiplication is written.
  3. Now we need to multiply all the digits of the first number by the next digit of the second number and write the result one more line below, but this result needs to be shifted one digit to the left; if you look at the table, this is the second sequence of zeros from the top.
  4. The same must be done for subsequent digits, each time moving one digit to the left, and if you look at the table, you can say that one cell to the left.
  5. We have four binary numbers that we now need to add and get the result. We recently looked at addition, there shouldn't be any problems.

In general, the multiplication operation is not that difficult, you just need a little practice.

Boolean algebra operations

There are two very important concepts in Boolean algebra: true and false, the equivalent of which is zero and one in the binary number system. Boolean algebra operators expand the number of available operators over these values, let's take a look at them.

Logical AND or AND operation

The Logical AND or AND operation is equivalent to multiplying single-digit binary numbers.

1 AND 1 = 1; 1 AND 0 = 1; 0 AND 0 = 0; 0 AND 1 = 0.

1 AND 1 = 1 ;

1 AND 0 = 1 ;

0 AND 0 = 0 ;

0 AND 1 = 0.

The result of “Logical AND” will be one only if both values ​​are equal to one; in all other cases it will be zero.

Operation "Logical OR" or OR

The operation “Logical OR” or OR works on the following principle: if at least one value is equal to one, then the result will be one.

1 OR 1 = 1; 1 OR 0 = 1; 0 OR 1 = 1; 0 OR 0 = 0.

1 OR 1 = 1 ;

1 OR 0 = 1 ;

0 OR 1 = 1 ;

0 OR 0 = 0.

Exclusive OR or XOR operation

The operation "Exclusive OR" or XOR will give us a result of one only if one of the operands is equal to one and the second is equal to zero. If both operands are equal to zero, the result will be zero and even if both operands are equal to one, the result will be zero.

Purpose of the service. The service is designed to convert numbers from one number system to another online. 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 of the new number system until the remainder remains a number less 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 the octal (hexadecimal) number system, it is necessary to divide the binary number from the decimal point 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

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) 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.

  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 Binary SS
1011 Hexadecimal SS
1100 A
1101 B
1110 C
1111 D

E

F

Table for conversion to octal number system

Note 1

If you want to convert a number from one number system to another, then it is more convenient to first convert it to the decimal number system, and only then convert it from the decimal number system to any other number system.

    Rules for converting numbers from any number system to decimal

    In computing technology that uses machine arithmetic, the conversion of numbers from one number system to another plays an important role. Below we give the basic rules for such transformations (translations).

When converting a binary number to a decimal, you need to represent the binary number as a polynomial, each element of which is represented as the product of a digit of the number and the corresponding power of the base number, in this case $2$, and then you need to calculate the polynomial using the rules of decimal arithmetic:

$X_2=A_n \cdot 2^(n-1) + A_(n-1) \cdot 2^(n-2) + A_(n-2) \cdot 2^(n-3) + ... + A_2 \cdot 2^1 + A_1 \cdot 2^0$

Figure 1. Table 1

Example 1 Convert the number $11110101_2$ to the decimal number system.

$11110101_2 = 1 \cdot 27 + 1 \cdot 26 + 1 \cdot 25 + 1 \cdot 24 + 0 \cdot 23 + 1 \cdot 22 + 0 \cdot 21 + 1 \cdot 20 = 128 + 64 + 32 + 16 + 0 + 4 + 0 + 1 = 245_(10)$

    To convert a number from the octal number system to the decimal number system, you need to represent it as a polynomial, each element of which is represented as the product of a digit of the number and the corresponding power of the base number, in this case $8$, and then you need to calculate the polynomial according to the rules of decimal arithmetic:

    $X_8 = A_n \cdot 8^(n-1) + A_(n-1) \cdot 8^(n-2) + A_(n-2) \cdot 8^(n-3) + ... + A_2 \cdot 8^1 + A_1 \cdot 8^0$

Figure 2. Table 2

Example 2

Convert the number $75013_8$ to the decimal number system.

Example 1 Using the given table of $2$ powers of the base $8$, we represent the number as a polynomial:

$75013_8 = 7\cdot 8^4 + 5 \cdot 8^3 + 0 \cdot 8^2 + 1 \cdot 8^1 + 3 \cdot 8^0 = 31243_(10)$

    To convert a number from hexadecimal to decimal, you need to represent it as a polynomial, each element of which is represented as the product of a digit of the number and the corresponding power of the base number, in this case $16$, and then you need to calculate the polynomial according to the rules of decimal arithmetic:

    $X_(16) = A_n \cdot 16^(n-1) + A_(n-1) \cdot 16^(n-2) + A_(n-2) \cdot 16^(n-3) + . .. + A_2 \cdot 16^1 + A_1 \cdot 16^0$

Figure 3. Table 3

Example 3

Convert the number $FFA2_(16)$ to the decimal number system.

Example 1 Using the given table of $3$ powers of the base $8$, we represent the number as a polynomial:

$FFA2_(16) = 15 \cdot 16^3 + 15 \cdot 16^2 + 10 \cdot 16^1 + 2 \cdot 16^0 =61440 + 3840 + 160 + 2 = 65442_(10)$

Rules for converting numbers from the decimal number system to another

  • To convert a number from the decimal number system to the binary system, it must be sequentially divided by $2$ until there is a remainder less than or equal to $1$. A number in the binary system is represented as a sequence of the last result of division and the remainders from division in reverse order.

Example 4

Convert the number $22_(10)$ to the binary number system.

Solution:

Figure 4.

$22_{10} = 10110_2$

  • To convert a number from the decimal number system to octal, it must be sequentially divided by $8$ until there is a remainder less than or equal to $7$. A number in the octal number system is represented as a sequence of digits of the last division result and the remainders from the division in reverse order.

Example 5

Convert the number $571_(10)$ to the octal number system.

Solution:

Figure 5.

$571_{10} = 1073_8$

  • To convert a number from the decimal number system to the hexadecimal system, it must be successively divided by $16$ until there is a remainder less than or equal to $15$. A number in the hexadecimal system is represented as a sequence of digits of the last division result and the remainder of the division in reverse order.

Example 6

Convert the number $7467_(10)$ to hexadecimal number system.

Solution:

Figure 6.

$7467_(10) = 1D2B_(16)$

    In order to convert a proper fraction from a decimal number system to a non-decimal number system, it is necessary to sequentially multiply the fractional part of the number being converted by the base of the system to which it needs to be converted. Fractions in the new system will be represented as whole parts of products, starting with the first.

    For example: $0.3125_((10))$ in octal number system will look like $0.24_((8))$.

    In this case, you may encounter a problem when a finite decimal fraction can correspond to an infinite (periodic) fraction in the non-decimal number system. In this case, the number of digits in the fraction represented in the new system will depend on the required accuracy. It should also be noted that integers remain integers, and proper fractions remain fractions in any number system.

Rules for converting numbers from a binary number system to another

  • To convert a number from the binary number system to octal, it must be divided into triads (triples of digits), starting with the least significant digit, if necessary, adding zeros to the leading triad, then replace each triad with the corresponding octal digit according to Table 4.

Figure 7. Table 4

Example 7

Convert the number $1001011_2$ to the octal number system.

Solution. Using Table 4, we convert the number from the binary number system to octal:

$001 001 011_2 = 113_8$

  • To convert a number from the binary number system to hexadecimal, it should be divided into tetrads (four digits), starting with the least significant digit, if necessary, adding zeros to the most significant tetrad, then replace each tetrad with the corresponding octal digit according to Table 4.

In this article I will tell you the basics of computer technology - this is a binary system. This is the lowest level, these are the numbers by which the computer works. And you will learn how to transfer from one system

Table 1 - Representation of numbers in various systems
calculus (beginning)

Number systems

Decimal

Binary

Octal

Hexadecimal

BCD

To convert from decimal to binary, you have two options.

1) For example, the number 37 needs to be converted from the decimal system to the binary system, then you need to divide it by two, and then check the remainder of the division. If the remainder is odd, then we write one at the bottom and the next division cycle goes through an even number; if the remainder of the division is even, then we write zero. At the end you must get 1. And now we convert the resulting result into binary, and the number goes from right to left.

Step by step: 37 is an odd number, which means 1 , then 36/2 = 18. The number is even, which means 0. 18/2 = 9 is an odd number, which means 1 , then 8/2 = 4. The number is even, read 0. 4/2 = 2, an even number means 0, 2/2 = 1.

So we got the number. Don't forget to count from right to left: 100101 - now we have a number in the binary system. In general, this is written as a division in a column, as you see in the figure below:

2) But there is a second way. I like him better. Transfer from one system to another is as follows:

where ai is the i-th digit of the number;
k - the number of digits in the fractional part of the number;
m - the number of digits in the integer part of the number;
N is the base of the number system.

The base of the number system N shows how many times the “weight” of the i-th digit is greater than the “weight” (i-1) of the digit. The integer part of the number is separated from the fractional part by a dot (comma).

The integer part of the number AN1, with the base N1, is converted to the number system with the base N2 by sequentially dividing the integer part of the number AN1 by the base N2 written as a number with the base N1, until a remainder is obtained. The resulting part is again divided by the base N2, and this process must repeat until the particle becomes smaller than the divisor. The resulting remainders from division and the last part are written in the reverse order obtained during division. The generated number will be an integer with base N2.

The fractional part of the number AN1, with base N1, is converted into a number system with base N2 by sequentially multiplying the fractional part of the number AN1 by base N2, written as a number with base N1. With each multiplication, the integer part of the product is taken in the form of the next digit of the corresponding digit, and the fractional part of the remaining is taken as a new multiplication. The number of multiplications determines the digit capacity of the resulting result, representing the fractional part of the number AN1 in the N2 number system. The fractional part of a number is often represented inaccurately when translated.

Let's do this with an example:

Convert from decimal to binary

37 in decimal must be converted to binary. Let's work with degrees:

2 0 = 1
2 1 = 2
2 2 = 4
2 3 = 8
2 4 = 16
2 5 = 32
2 6 = 64
2 7 = 128
2 8 = 256
2 9 = 512
2 10 = 1024 and so on... ad infinitum

This means: 37 - 32 = 5. 5 - 4 = 1. The answer is as follows in binary: 100101.

Let's convert the number 658 from decimal to binary:

658-512=146
146-128=18
18-16=2. In the binary system the number will look like: 1010010010.

Converting from decimal to octal

If you need to convert from decimal to octal, you must first convert to binary, and then convert from binary to octal. That is, it’s easier this way, although you can translate it right away. Using an algorithm similar to the one for converting to binary, see above.

Convert from decimal to hexadecimal

If you need to convert from decimal to hexadecimal, you must first convert to binary and then convert from binary to hexadecimal. That is, it’s easier this way, although you can translate it right away. Using an algorithm similar to the one for converting to binary, see above.

Converting from binary to octal

To convert a number from binary to octal, you need to split the binary into three numbers.

For example, the resulting number 1010010010 is divided into three numbers, and the division goes from right to left: 1,010,010,010 = 1222. See the table at the very beginning.

Converting from binary to hexadecimal

To convert a number from binary to hexadecimal, you need to divide it into tetrads (four each)

10 1001 0010 = 292

Here are a few examples for you to look through:

Conversion is from binary to octal, then to hexadecimal, and then from binary to decimal

(2) = 11101110
(8) = 11 101 110 = 276
(16) = 1110 1110 = EE
(10) = 1*128+ 1*64+ 1*32+ 0 +1*8 + 1*4 + 1*2+ 0= 238
3) (8) = 657

Conversion is carried out from hexadecimal to binary, then to octal, and then from binary to decimal

(16) = 6E8
(2) = 110 1110 1000
(8) = 11 011 101 000 = 2250
(10) = 1*1024+1*512+ 0 +1*128+ 1*64+ 1*32+ 8 = 1768

1. Ordinal counting in various number systems.

In modern life, we use positional number systems, that is, systems in which the number denoted by a digit depends on the position of the digit in the notation of the number. Therefore, in the future we will talk only about them, omitting the term “positional”.

In order to learn how to convert numbers from one system to another, we will understand how sequential recording of numbers occurs using the example of the decimal system.

Since we have a decimal number system, we have 10 symbols (digits) to construct numbers. We start counting: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. The numbers are over. We increase the bit depth of the number and reset the low-order digit: 10. Then we increase the low-order digit again until all the digits are gone: 11, 12, 13, 14, 15, 16, 17, 18, 19. We increase the high-order digit by 1 and reset the low-order digit: 20. When we use all the digits for both digits (we get the number 99), we again increase the digit capacity of the number and reset the existing digits: 100. And so on.

Let's try to do the same in the 2nd, 3rd and 5th systems (we introduce the notation for the 2nd system, for the 3rd, etc.):

0 0 0 0
1 1 1 1
2 10 2 2
3 11 10 3
4 100 11 4
5 101 12 10
6 110 20 11
7 111 21 12
8 1000 22 13
9 1001 100 14
10 1010 101 20
11 1011 102 21
12 1100 110 22
13 1101 111 23
14 1110 112 24
15 1111 120 30

If the number system has a base greater than 10, then we will have to enter additional characters; it is customary to enter letters of the Latin alphabet. For example, for the 12-digit system, in addition to ten digits, we need two letters ( and ):

0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10
11
12 10
13 11
14 12
15 13

2. Conversion from the decimal number system to any other.

To convert a positive integer decimal number to a number system with a different base, you need to divide this number by the base. Divide the resulting quotient by the base again, and further until the quotient is less than the base. As a result, write down in one line the last quotient and all remainders, starting from the last.

Example 1. Let's convert the decimal number 46 to the binary number system.

Example 2. Let's convert the decimal number 672 to the octal number system.

Example 3. Let's convert the decimal number 934 to the hexadecimal number system.

3. Conversion from any number system to decimal.

In order to learn how to convert numbers from any other system to decimal, let's analyze the usual notation for a decimal number.
For example, the decimal number 325 is 5 units, 2 tens and 3 hundreds, i.e.

The situation is exactly the same in other number systems, only we will multiply not by 10, 100, etc., but by the powers of the base of the number system. For example, let's take the number 1201 in the ternary number system. Let's number the digits from right to left starting from zero and imagine our number as the sum of the products of a digit and three to the power of the digit of the number:

This is the decimal notation of our number, i.e.

Example 4. Let's convert the octal number 511 to the decimal number system.

Example 5. Let's convert the hexadecimal number 1151 to the decimal number system.

4. Conversion from the binary system to the system with the base “power of two” (4, 8, 16, etc.).

To convert a binary number into a number with a power of two base, it is necessary to divide the binary sequence into groups according to the number of digits equal to the power from right to left and replace each group with the corresponding digit of the new number system.

For example, Let's convert the binary number 1100001111010110 to the octal system. To do this, we will divide it into groups of 3 characters starting from the right (since ), and then use the correspondence table and replace each group with a new number:

We learned how to build a correspondence table in step 1.

0 0
1 1
10 2
11 3
100 4
101 5
110 6
111 7

Those.

Example 6. Let's convert the binary number 1100001111010110 to hexadecimal.

0 0
1 1
10 2
11 3
100 4
101 5
110 6
111 7
1000 8
1001 9
1010 Binary SS
1011 Hexadecimal SS
1100 A
1101 B
1110 C
1111 D

5. Conversion from a system with the base “power of two” (4, 8, 16, etc.) to binary.

This translation is similar to the previous one, done in the opposite direction: we replace each digit with a group of digits in the binary system from the correspondence table.

Example 7. Let's convert the hexadecimal number C3A6 to the binary number system.

To do this, replace each digit of the number with a group of 4 digits (since ) from the correspondence table, supplementing the group with zeros at the beginning if necessary:




About the influence of sleep on human life

© Copyright 2024,
ctik.ru -About the influence of sleep on human life

  • Categories
  • Health
  • Aromatherapy
  • The quality of life
  • Dreams
  • Health
  • Aromatherapy
  • The quality of life
  • Dreams
  • Other
  • About the site
  • Site Map
  • Contacts
  • Advertising