Converting numbers from one number system to another online. Translation of text into digital code

Everyone knows that computers can perform calculations with large groups data at high speed. But not everyone knows that these actions depend on only two conditions: whether or not there is current and what voltage.

How does a computer manage to process such diverse information?
The secret lies in the binary system. All data enters the computer, presented in the form of units and zeros, each of which corresponds to one state of the electric wire: units - high voltage, zeros - low, or ones - the presence of voltage, zeros - its absence. The conversion of data into zeros and ones is called a binary conversion, and their final designation is called a binary code.
In decimal notation based on the decimal system used in Everyday life, numerical value represented by ten digits from 0 to 9, and each place in the number has a value ten times higher than the place to its right. To represent a number greater than nine in the decimal system, a zero is put in its place, and a unit is put in the next, more valuable place to the left. Similarly, in binary, where only two digits, 0 and 1, are used, each place is twice as valuable as the place to its right. Thus, in binary code, only zero and one can be represented as single numbers, and any number greater than one requires two places. After zero and one, the next three binary numbers are 10 (read one-zero) and 11 (read one-one) and 100 (read one-zero-zero). 100 binary is equivalent to 4 decimal. The top table on the right shows other BCD equivalents.
Any number can be expressed in binary, it just takes more space than in decimal notation. In the binary system, you can also write the alphabet, if you assign a certain number to each letter. binary number.

Two digits for four places
16 combinations can be made using dark and light balls, combining them in sets of four. If dark balls are taken as zeros, and light ones as ones, then 16 sets will turn out to be a 16-unit binary code, the numerical value of which is from zero to five ( see top table on page 27). Even with two kinds of balls in binary, you can build an infinite number of combinations by simply increasing the number of balls in each group - or the number of places in the numbers.

Bits and bytes

The smallest unit in computer processing, a bit is a unit of data that can have one of two possible conditions. For example, each of the ones and zeros (on the right) means 1 bit. A bit can be represented in other ways: by the presence or absence of electric current, a hole and its absence, the direction of magnetization to the right or left. Eight bits make up a byte. The 256 possible bytes can represent 256 characters and symbols. Many computers process bytes of data at the same time.

binary conversion. A four-digit binary code can represent decimal numbers from 0 to 15.

Code tables

When a binary code is used to denote letters of the alphabet or punctuation marks, code tables are required that indicate which code corresponds to which character. Several such codes have been compiled. Most PCs are configured with a seven-digit code called ASCII, or the American Standard Code for Information Interchange. The table on the right shows the ASCII codes for English alphabet. Other codes are for thousands of characters and alphabets from other languages ​​of the world.

Part of the ASCII code table

Let's figure out how translate texts into digital code? By the way, on our website you can convert any text into decimal, hexadecimal, binary code using the Online Code Calculator.

Text encoding.

According to computer theory, any text consists of individual characters. These characters include: letters, numbers, lowercase punctuation marks, special characters ("", №, (), etc.), they also include spaces between words.

Necessary knowledge base. The set of symbols with which I write down the text is called the ALPHABET.

The number of symbols taken in the alphabet represents its power.

The amount of information can be determined by the formula: N = 2b

  • N - the same power (set of characters),
  • b - Bit (weight of the taken symbol).

An alphabet in which there will be 256 can accommodate almost all the necessary characters. Such alphabets are called SUFFICIENT.

If we take an alphabet with a power of 256, and keep in mind that 256 \u003d 28

  • 8 bits is always called 1 byte:
  • 1 byte = 8 bits.

If we translate each character into a binary code, then this computer text code will take 1 byte.

How can textual information look like in computer memory?

Any text is typed on the keyboard, on the keyboard keys, we see signs familiar to us (numbers, letters, etc.). They enter the computer's RAM only in the form of a binary code. The binary code of each character looks like an eight-digit number, such as 00111111.

Since a byte is the smallest addressable memory unit, and the memory is addressed to each character separately, the convenience of such coding is obvious. However, 256 characters is a very convenient amount for any character information.

Naturally, the question arose: Which eight digit code belongs to each character? And how to translate text into digital code?

This process is conditional, and we have the right to come up with various ways to encode characters. Each character of the alphabet has its own number from 0 to 255. And each number is assigned a code from 00000000 to 11111111.

The encoding table is a "cheat sheet" in which the characters of the alphabet are indicated in accordance with the serial number. For various types Computers use different tables for encoding.

ASCII (or Asci), became international standard for personal computers. The table has two parts.

The first half is for an ASCII table. (It was the first half that became the standard.)

Compliance with the lexicographic order, that is, in the table, the letters (lowercase and uppercase) are indicated in strict alphabetical order, and the numbers in ascending order, is called the principle of sequential coding of the alphabet.

For the Russian alphabet, they also observe sequential coding principle.

Now, in our time, whole five coding systems Russian alphabet (KOI8-R, Windows. MS-DOS, Macintosh and ISO). Due to the number of encoding systems and the lack of one standard, misunderstandings often arise with the transfer of Russian text to its computer form.

One of the first standards for encoding the Russian alphabet and on personal computers they consider KOI8 ("Information exchange code, 8-bit"). This encoding was used in the mid-seventies on a series of ES computers, and since the mid-eighties, it has been used in the first UNIX operating systems translated into Russian.

Since the beginning of the nineties, the so-called time when operating system MS DOS, the CP866 coding system appears ("CP" stands for "Code Page", "code page").

Computer giant APPLE, with its innovation system, under which they worked (Mac OS), begin to use their own system for encoding the MAC alphabet.

The International Standards Organization (ISO) appoints another standard for the Russian language alphabet coding system called ISO 8859-5.

And the most common, nowadays, system for coding the alphabet, invented in Microsoft Windows, and is called CP1251.

Since the second half of the nineties, the problem of the standard for translating text into digital code for the Russian language and not only was solved by introducing a system called Unicode into the standard. It is represented by a sixteen-bit encoding, which means that exactly two bytes of RAM are allocated for each character. Of course, with this encoding, memory costs are doubled. However, such a code system allows you to convert up to 65536 characters into an electronic code.

The specificity of the standard Unicode system is the inclusion of absolutely any alphabet, be it existing, extinct, invented. Ultimately, absolutely any alphabet, in addition to this, the Unicode system, includes a lot of mathematical, chemical, musical and general symbols.

Let's use an ASCII table to see what a word might look like in your computer's memory.

It often happens that your text, which is written in letters from the Russian alphabet, is not readable, this is due to the difference in alphabet coding systems on computers. This is a very common problem that is found quite often.

binary code- this is a representation of information in a combination of 2 characters 1 or 0, as they say in programming, yes or no, true or false, true or false. It is difficult for an ordinary person to understand how information can be represented in the form of zeros and ones. I will try to clarify this situation a little.

In fact, binary code is easy! For example, any letter of the alphabet can be represented as a set of zeros and ones. For example, a letter H the Latin alphabet will look like this in the binary system - 01001000, the letter E– 01000101, beech L has the following binary representation - 01001100, P – 01010000.

Now it is not difficult to guess what to write English word HELP in machine language, you need to use the following binary code:

01001000 01000101 01001100 01010000

It is this code that our home computer uses for its work. To an ordinary person it is very difficult to read such code, but for computers it is the most understandable.

Binary code (machine code) nowadays it is used in programming, because the computer works precisely thanks to the binary code. But do not think that the programming process is reduced to a set of ones and zeros. Specifically, to simplify understanding between a person and a computer, programming languages ​​\u200b\u200b(C++, BASIC, etc.) were invented. The programmer writes a program in a language he understands, and then, with the help of a special compiler program, translates his creation into machine code, which starts the computer.

We translate the natural number of the decimal number system into binary

We take the right number, for me it will be 5, divide the number by 2:
5: 2 = 2,5 there is a remainder, so the first number of the binary code will be 1 (if not - 0 ). Throw away the remainder and again divide the number by 2 :
2: 2 = 1 the answer is without a remainder, which means that the second number of the binary code will be - 0. Divide the result by 2 again:
1: 2 = 0.5 the number turned out with a remainder, then we write 1 .
Well, since the result is 0 can no longer be divided, the binary code is ready and as a result we got the number of the binary code 101 . I think we have learned to translate from decimal to binary, now we will learn to do the opposite.

Converting a number from binary to decimal

Here, too, it is quite simple, let's number our binary number with you, you need to start from zero from the end of the number.

101 is 1^2 0^1 1^0.

What came of it? We betrayed degrees to numbers! now according to the formula:

(x * 2^y) + (x * 2^y) + (x * 2^y)

where x- ordinal number of binary code
y- the degree of this number.
The formula will expand depending on the size of your number.
We get:

(1 * 2^2) + (0 * 2^1) + (1 * 2^0) = 4 + 0 + 1 = 5.

History of the binary number system

For the first time, the binary system was proposed by Leibitz, he believed that this system help with difficult mathematical calculations, and in general will benefit science. But according to some reports, before Leibitz proposed a binary number system in China, an inscription appeared on the wall that could be deciphered using a binary code. Long and short sticks were drawn on this inscription, and if we assume that the long one is 1 and the short one is 0, it is quite possible that in China the idea of ​​a binary code went many years before its invention. Although the decoding of the code found on the wall revealed a simple natural number there, the fact remains.

The result has already been received!

Number systems

There are positional and non-positional number systems. Arabic system The calculus we use in everyday life is positional, while the Roman one is not. In positional number systems, the position of a number uniquely determines the magnitude of the number. 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 this case it is 10). The values ​​of the position of the given number are taken as degrees.

Consider the real decimal number 1287.923. We number it starting from the zero position of the number from the decimal point to the left and to the 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, 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 a set of digits (0,1,2,3,4,5,6,7,8,9), in the octal number system it consists of a set of digits (0,1, 2,3,4,5,6,7), in the binary system - from a set of digits (0,1), in a 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 numbers 10,11,12,13,14,15. In Table 1 numbers are represented 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 translate numbers from one number system to another, the easiest way is to first convert the number to the decimal number system, and then, from the decimal number system, translate it into the required number system.

Converting numbers from any number system to 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. Decision:

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. Decision:

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

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

Converting numbers from a decimal number system to another number system

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

The integer part of the number is translated from the decimal SS to another number system - by successive division of the integer part of the number by the base of the number system (for binary SS - by 2, for 8-digit SS - by 8, for 16-digit - by 16, etc. ) to obtain a whole remainder, less than the base of the SS.

Example 4 . Let's translate 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 the remainder is 1. Further, the number 79, when divided by 2, gives the quotient 39 and the remainder is 1, and so on. As a result, by constructing a number from the remainder of the division (from right to left), we get 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 decimal SS to octal SS, you need to sequentially divide the number by 8 until you get an integer remainder less than 8. As a result, building a number from the remainder of the division (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 translate 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, we got the remainders 4, 12, 13, 9. In the hexadecimal number system, the number 12 corresponds to C, the number 13 - D. Therefore, our hexadecimal number is 4CD9.

To convert correct decimal fractions (a real number with a zero integer part) into a number system with base s, this number must be successively multiplied by s until the fractional part is pure zero, or we get the required number of digits. If the multiplication results in a number with an integer part other than zero, 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 translate 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 successively 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, when multiplied, a number with a zero integer part is obtained, then zero is written to the left of it. The multiplication process continues until a pure zero is obtained in the fractional part or the required number of digits is obtained. Writing bold numbers (Fig. 4) from top to bottom, we get the required number in the binary system: 0. 0011011 .

Therefore, we can write:

0.214 10 =0.0011011 2 .

Example 8 . Let's translate the number 0.125 from the decimal number system to the 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 successively multiplied by 2. In the third stage, 0 was obtained. Therefore, the following result was obtained:

0.125 10 =0.001 2 .

Example 9 . Let's translate 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 C and B correspond to the numbers 12 and 11. Therefore, we have:

0.214 10 =0.36C8B4 16 .

Example 10 . Let's translate the number 0.512 from the decimal number system to the 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 translate 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). Combining these results, we get:

159.125 10 =10011111.001 2 .

Example 12 . Let's translate 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 get.

Service assignment. 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 translate the number. You can enter both integers and numbers with a comma.

Number

Translation 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 either whole numbers, such as 34 , or fractional numbers, such as 637.333 . For fractional numbers, the accuracy of the translation 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 character 0...9, A, B, ..., F. Such a representation can be denoted in different ways, here only the character "h" is used after the last hexadecimal digit. For example, A5h. In program texts, the same number can be denoted both as 0xA5 and 0A5h, depending on the syntax of the programming language. A non-significant zero (0) is added to the left of the most significant hexadecimal digit represented by a letter to distinguish between numbers and symbolic names.
Decimals (decimal) numbers - each byte (word, double word) is represented by an ordinary number, and the sign of the decimal representation (letter "d") is usually omitted. The byte from 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 sometimes has to be done.
Octal (octal) numbers - each triple of bits (separation starts from the least significant) is written as a number 0-7, at the end the sign "o" is put. The same number would be written as 245o. The octal system is inconvenient in that the byte cannot be divided equally.

Algorithm for converting numbers from one number system to another

The conversion of integer 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 less than the base of the new number system. The new number is written as the remainder of the division, starting with the last one.
Correct translation decimal fraction to another PSS is carried out by multiplying only the fractional part of the number by the basis of the new number system until all zeros remain in the fractional part or until the specified translation accuracy is reached. As a result of each multiplication operation, one digit of the new number is formed, starting from the highest.
The translation of an improper fraction is carried out according to the 1st and 2nd rules. The integer and fractional parts are written together, separated by a comma.

Example #1.



Translation from 2 to 8 to 16 number system.
These systems are multiples of two, therefore, the translation is carried out using the correspondence table (see below).

To convert a number from a binary number system to an octal (hexadecimal) number, it is necessary to divide the binary number into groups of three (four for hexadecimal) digits from a comma to the right and left, complementing the extreme groups with zeros if necessary. Each group is replaced by the corresponding octal or hexadecimal digit.

Example #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 hexadecimal, you must divide the number into parts, four digits each, following the same rules.
Example #3. 1010111010.1011 = 10.1011.1010.1011 = 2B12.13 HEX
here 0010=2; 1011=B; 1010=12; 1011=13

The conversion of numbers from 2, 8 and 16 to the decimal system is carried out by breaking the number into separate ones and multiplying it by the base of the system (from which the number is translated) raised to the power corresponding to its ordinal number in the translated number. In this case, the numbers are numbered to the left of the decimal point (the first number has the number 0) with increasing, and to the right with decreasing (ie, with a negative sign). The results obtained are added up.

Example #4.
Example of converting 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 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 converting from hexadecimal to decimal number system. 108.5 16 = 1 16 2 +0 16 1 +8 16 0 + 5 16 -1 = 256+0+8+0.3125 = 264.3125 10

Once again, we repeat the algorithm for translating numbers from one number system to another PSS

  1. From the decimal number system:
    • divide the number by the base of the number system being translated;
    • find the remainder after dividing the integer part of the number;
    • write down all remainders from division in reverse order;
  2. From the binary system
    • To convert to the decimal number system, you need to find the sum of the products of base 2 by the corresponding degree of discharge;
    • To convert a number to octal, you need to break the number into triads.
      For example, 1000110 = 1000 110 = 106 8
    • To convert a number from binary to hexadecimal, you need to divide the number into groups of 4 digits.
      For example, 1000110 = 100 0110 = 46 16
The system is called positional., for which the significance or weight of a digit depends on its location in the number. The relationship between systems is expressed in a table.
Table of correspondence of number systems:
Binary SSHexadecimal SS
0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
1001 9
1010 A
1011 B
1100 C
1101 D
1110 E
1111 F

Table for converting to octal number system

Have questions?

Report a typo

Text to be sent to our editors: