Encrypting words in binary code. Coding of text information. Converting a binary system number to decimal


Aryabhata
Cyrillic
Greek Georgian
Ethiopian
Jewish
Akshara-sankhya Other Babylonian
Egyptian
Etruscan
Roman
Danube Attic
Kipu
Mayan
Aegean
KPPU symbols Positional , , , , , , , , , , Nega-positional Symmetrical Mixed systems Fibonacci Non-positional Unit (unary)

Binary number system- positional number system with base 2. Thanks to its direct implementation in digital electronic circuits using logic gates, the binary system is used in almost all modern computers and other computing electronic devices.

Binary notation of numbers

In the binary number system, numbers are written using two symbols ( 0 And 1 ). To avoid confusion as to which number system the number is written in, it is provided with an indicator at the bottom right. For example, a number in the decimal system 5 10 , in binary 101 2 . Sometimes a binary number is denoted by a prefix 0b or symbol & (ampersand), For example 0b101 or accordingly &101 .

In the binary number system (as in other number systems except decimal), the digits are read one at a time. For example, the number 101 2 is pronounced “one zero one.”

Integers

A natural number written in binary number system as (a n − 1 a n − 2 … a 1 a 0) 2 (\displaystyle (a_(n-1)a_(n-2)\dots a_(1)a_(0))_(2)), has the meaning:

(a n − 1 a n − 2 … a 1 a 0) 2 = ∑ k = 0 n − 1 a k 2 k , (\displaystyle (a_(n-1)a_(n-2)\dots a_(1)a_( 0))_(2)=\sum _(k=0)^(n-1)a_(k)2^(k),)

Negative numbers

Negative binary numbers are denoted in the same way as decimal numbers: by a “−” sign in front of the number. Namely, a negative integer written in binary number system (− a n − 1 a n − 2 … a 1 a 0) 2 (\displaystyle (-a_(n-1)a_(n-2)\dots a_(1)a_(0))_(2)), has the value:

(− a n − 1 a n − 2 … a 1 a 0) 2 = − ∑ k = 0 n − 1 a k 2 k . (\displaystyle (-a_(n-1)a_(n-2)\dots a_(1)a_(0))_(2)=-\sum _(k=0)^(n-1)a_( k)2^(k).)

additional code.

Fractional numbers

A fractional number written in binary number system as (a n − 1 a n − 2 … a 1 a 0 , a − 1 a − 2 … a − (m − 1) a − m) 2 (\displaystyle (a_(n-1)a_(n-2)\dots a_(1)a_(0),a_(-1)a_(-2)\dots a_(-(m-1))a_(-m))_(2)), has the value:

(a n − 1 a n − 2 … a 1 a 0 , a − 1 a − 2 … a − (m − 1) a − m) 2 = ∑ k = − m n − 1 a k 2 k , (\displaystyle (a_( n-1)a_(n-2)\dots a_(1)a_(0),a_(-1)a_(-2)\dots a_(-(m-1))a_(-m))_( 2)=\sum _(k=-m)^(n-1)a_(k)2^(k),)

Adding, subtracting and multiplying binary numbers

Addition table

An example of column addition (the decimal expression 14 10 + 5 10 = 19 10 in binary looks like 1110 2 + 101 2 = 10011 2):

Example of column multiplication (the decimal expression 14 10 * 5 10 = 70 10 in binary looks like 1110 2 * 101 2 = 1000110 2):

Starting with the number 1, all numbers are multiplied by two. The dot that comes after the 1 is called the binary dot.

Converting binary numbers to decimal

Let's say we're given a binary number 110001 2 . To convert to decimal, write it as a sum by digits as follows:

1 * 2 5 + 1 * 2 4 + 0 * 2 3 + 0 * 2 2 + 0 * 2 1 + 1 * 2 0 = 49

Same thing a little differently:

1 * 32 + 1 * 16 + 0 * 8 + 0 * 4 + 0 * 2 + 1 * 1 = 49

You can write this in table form like this:

512 256 128 64 32 16 8 4 2 1
1 1 0 0 0 1
+32 +16 +0 +0 +0 +1

Move from right to left. Under each binary unit, write its equivalent on the line below. Add the resulting decimal numbers. Thus, the binary number 110001 2 is equivalent to the decimal number 49 10.

Converting fractional binary numbers to decimal

Need to convert the number 1011010,101 2 to the decimal system. Let's write this number as follows:

1 * 2 6 + 0 * 2 5 + 1 * 2 4 + 1 * 2 3 + 0 * 2 2 + 1 * 2 1 + 0 * 2 0 + 1 * 2 −1 + 0 * 2 −2 + 1 * 2 −3 = 90,625

Same thing a little differently:

1 * 64 + 0 * 32 + 1 * 16 + 1 * 8 + 0 * 4 + 1 * 2 + 0 * 1 + 1 * 0,5 + 0 * 0,25 + 1 * 0,125 = 90,625

Or according to the table:

64 32 16 8 4 2 1 0.5 0.25 0.125
1 0 1 1 0 1 0 , 1 0 1
+64 +0 +16 +8 +0 +2 +0 +0.5 +0 +0.125

Transformation by Horner's method

In order to convert numbers from binary to decimal using this method, you need to sum the numbers from left to right, multiplying the previously obtained result by the base of the system (in this case, 2). Horner's method is usually used to convert from binary to decimal system. The reverse operation is difficult, as it requires skills in addition and multiplication in the binary number system.

For example, binary number 1011011 2 converted to decimal system as follows:

0*2 + 1 = 1
1*2 + 0 = 2
2*2 + 1 = 5
5*2 + 1 = 11
11*2 + 0 = 22
22*2 + 1 = 45
45*2 + 1 = 91

That is, in the decimal system this number will be written as 91.

Converting the fractional part of numbers using Horner's method

The digits are taken from the number from right to left and divided by the number system base (2).

For example 0,1101 2

(0 + 1 )/2 = 0,5
(0,5 + 0 )/2 = 0,25
(0,25 + 1 )/2 = 0,625
(0,625 + 1 )/2 = 0,8125

Answer: 0.1101 2 = 0.8125 10

Converting decimal numbers to binary

Let's say we need to convert the number 19 to binary. You can use the following procedure:

19/2 = 9 with remainder 1
9/2 = 4 with remainder 1
4/2 = 2 without remainder 0
2/2 = 1 without remainder 0
1/2 = 0 with remainder 1

So we divide each quotient by 2 and write the remainder at the end of the binary notation. We continue dividing until the quotient is 0. We write the result from right to left. That is, the bottom digit (1) will be the leftmost, etc. As a result, we get the number 19 in binary notation: 10011 .

Converting fractional decimal numbers to binary

If the original number has an integer part, then it is converted separately from the fractional part. Converting a fractional number from the decimal number system to the binary system is carried out using the following algorithm:

  • The fraction is multiplied by the base of the binary number system (2);
  • In the resulting product, the integer part is isolated, which is taken as the most significant digit of the number in the binary number system;
  • The algorithm ends if the fractional part of the resulting product is equal to zero or if the required calculation accuracy is achieved. Otherwise, calculations continue on the fractional part of the product.

Example: You need to convert a fractional decimal number 206,116 to a fractional binary number.

Translation of the whole part gives 206 10 =11001110 2 according to the previously described algorithms. We multiply the fractional part of 0.116 by base 2, entering the integer parts of the product into the decimal places of the desired fractional binary number:

0,116 2 = 0 ,232
0,232 2 = 0 ,464
0,464 2 = 0 ,928
0,928 2 = 1 ,856
0,856 2 = 1 ,712
0,712 2 = 1 ,424
0,424 2 = 0 ,848
0,848 2 = 1 ,696
0,696 2 = 1 ,392
0,392 2 = 0 ,784
etc.

Thus 0.116 10 ≈ 0, 0001110110 2

We get: 206.116 10 ≈ 11001110.0001110110 2

Applications

In digital devices

The binary system is used in digital devices because it is the simplest and meets the requirements:

  • The fewer values ​​there are in the system, the easier it is to manufacture individual elements that operate on these values. In particular, two digits of the binary number system can be easily represented by many physical phenomena: there is a current (the current is greater than the threshold value) - there is no current (the current is less than the threshold value), the magnetic field induction is greater than the threshold value or not (the magnetic field induction is less than the threshold value) etc.
  • The fewer states an element has, the higher the noise immunity and the faster it can operate. For example, to encode three states through the magnitude of voltage, current or magnetic field induction, you will need to introduce two threshold values ​​and two comparators.

In computing, writing negative binary numbers in two's complement is widely used. For example, the number −5 10 could be written as −101 2 but would be stored as 2 on a 32-bit computer.

In the English system of measures

When indicating linear dimensions in inches, binary fractions are traditionally used rather than decimal, for example: 5¾″, 7 15/16″, 3 11/32″, etc.

Generalizations

The binary number system is a combination of the binary coding system and an exponential weighting function with a base equal to 2. It should be noted that a number can be written in binary code, and the number system may not be binary, but with a different base. Example: BCD encoding, in which decimal digits are written in binary and the number system is decimal.

Story

  • A complete set of 8 trigrams and 64 hexagrams, analogous to 3-bit and 6-bit numerals, was known in ancient China in the classical texts of the Book of Changes. The order of hexagrams in book of changes, arranged in accordance with the values ​​of the corresponding binary digits (from 0 to 63), and the method for obtaining them was developed by the Chinese scientist and philosopher Shao Yong in the 11th century. However, there is no evidence to suggest that Shao Yun understood the rules of binary arithmetic, arranging two-character tuples in lexicographical order.
  • Sets, which are combinations of binary digits, were used by Africans in traditional divination (such as Ifa) along with medieval geomancy.
  • In 1854, English mathematician George Boole published a landmark paper describing algebraic systems as applied to logic, which is now known as Boolean algebra or algebra of logic. His logical calculus was destined to play an important role in the development of modern digital electronic circuits.
  • In 1937, Claude Shannon submitted his Ph.D. thesis for defense. Symbolic analysis of relay and switching circuits in which Boolean algebra and binary arithmetic were used in relation to electronic relays and switches. All modern digital technology is essentially based on Shannon's dissertation.
  • In November 1937, George Stibitz, who later worked at Bell Labs, created the “Model K” computer based on relays. K itchen", the kitchen where the assembly was carried out), which performed binary addition. In late 1938, Bell Labs launched a research program led by Stiebitz. The computer created under his leadership, completed on January 8, 1940, was able to perform operations with complex numbers. During a demonstration at the American Mathematical Society conference at Dartmouth College on September 11, 1940, Stibitz demonstrated the ability to send commands to a remote complex number calculator over a telephone line using a teletype machine. This was the first attempt to use a remote computer via a telephone line. Conference participants who witnessed the demonstration included John von Neumann, John Mauchly and Norbert Wiener, who later wrote about it in their memoirs.

see also

Notes

  1. Popova Olga Vladimirovna. Computer Science Textbook (undefined) .

Binary code is a form of recording information in the form of ones and zeros. This is positional with a base of 2. Today, binary code (the table presented a little below contains some examples of writing numbers) is used in all digital devices without exception. Its popularity is explained by the high reliability and simplicity of this form of recording. Binary arithmetic is very simple, and accordingly, it is easy to implement at the hardware level. components (or, as they are also called, logical) are very reliable, since they operate in only two states: logical one (there is current) and logical zero (no current). Thus, they compare favorably with analog components, the operation of which is based on transient processes.

How is binary notation composed?

Let's figure out how such a key is formed. One bit of binary code can contain only two states: zero and one (0 and 1). When using two bits, it becomes possible to write four values: 00, 01, 10, 11. A three-bit entry contains eight states: 000, 001 ... 110, 111. As a result, we find that the length of the binary code depends on the number of bits. This expression can be written using the following formula: N =2m, where: m is the number of digits, and N is the number of combinations.

Types of binary codes

In microprocessors, such keys are used to record various processed information. The width of the binary code can significantly exceed its built-in memory. In such cases, long numbers occupy several storage locations and are processed using several commands. In this case, all memory sectors that are allocated for multi-byte binary code are considered as a single number.

Depending on the need to provide this or that information, the following types of keys are distinguished:

  • unsigned;
  • direct integer character codes;
  • signed inverses;
  • sign additional;
  • Gray code;
  • Gray Express code;
  • fractional codes.

Let's take a closer look at each of them.

Unsigned binary code

Let's figure out what this type of recording is. In unsigned integer codes, each digit (binary) represents a power of two. In this case, the smallest number that can be written in this form is zero, and the maximum can be represented by the following formula: M = 2 n -1. These two numbers completely define the range of the key that can be used to express such a binary code. Let's look at the capabilities of the mentioned recording form. When using this type of unsigned key, consisting of eight bits, the range of possible numbers will be from 0 to 255. A sixteen-bit code will have a range from 0 to 65535. In eight-bit processors, two memory sectors are used to store and write such numbers, which are located in adjacent destinations . Special commands provide work with such keys.

Direct integer signed codes

In this type of binary key, the most significant bit is used to record the sign of the number. Zero corresponds to a plus, and one corresponds to a minus. As a result of the introduction of this digit, the range of encoded numbers shifts to the negative side. It turns out that an eight-bit signed integer binary key can write numbers in the range from -127 to +127. Sixteen-bit - in the range from -32767 to +32767. Eight-bit microprocessors use two adjacent sectors to store such codes.

The disadvantage of this form of recording is that the sign and digital bits of the key must be processed separately. The algorithms of programs working with these codes turn out to be very complex. To change and highlight sign bits, it is necessary to use mechanisms for masking this symbol, which contributes to a sharp increase in the size of the software and a decrease in its performance. In order to eliminate this drawback, a new type of key was introduced - a reverse binary code.

Signed reverse key

This form of recording differs from direct codes only in that the negative number in it is obtained by inverting all the bits of the key. In this case, the digital and sign bits are identical. Thanks to this, algorithms for working with this type of code are significantly simplified. However, the reverse key requires a special algorithm to recognize the first-digit character and calculate the absolute value of the number. As well as restoring the sign of the resulting value. Moreover, in the reverse and forward codes of numbers, two keys are used to write zero. Despite the fact that this value does not have a positive or negative sign.

Signed two's complement binary number

This type of record does not have the listed disadvantages of previous keys. Such codes allow direct summation of both positive and negative numbers. In this case, no analysis of the sign bit is carried out. All this is made possible by the fact that complementary numbers are a natural ring of symbols, rather than artificial formations such as forward and backward keys. Moreover, an important factor is that it is extremely easy to perform complement calculations in binary codes. To do this, just add one to the reverse key. When using this type of sign code, consisting of eight digits, the range of possible numbers will be from -128 to +127. A sixteen-bit key will have a range from -32768 to +32767. Eight-bit processors also use two adjacent sectors to store such numbers.

Binary two's complement code is interesting because of its observable effect, which is called the sign propagation phenomenon. Let's figure out what this means. This effect is that in the process of converting a single-byte value into a double-byte one, it is enough to assign the values ​​of the sign bits of the low byte to each bit of the high byte. It turns out that you can use the most significant bits to store the signed one. In this case, the value of the key does not change at all.

Gray code

This form of recording is essentially a one-step key. That is, in the process of transition from one value to another, only one bit of information changes. In this case, an error in reading data leads to a transition from one position to another with a slight time shift. However, obtaining a completely incorrect result of the angular position with such a process is completely excluded. The advantage of such code is its ability to mirror information. For example, by inverting the most significant bits, you can simply change the counting direction. This happens thanks to the Complement control input. In this case, the output value can be either increasing or decreasing for one physical direction of axis rotation. Since the information recorded in the Gray key is exclusively encoded in nature, which does not carry real numerical data, before further work it is necessary to first convert it into the usual binary form of recording. This is done using a special converter - the Gray-Binar decoder. This device is easily implemented using elementary logic elements in both hardware and software.

Gray Express Code

Gray's standard one-step key is suitable for solutions that are represented as numbers, two. In cases where it is necessary to implement other solutions, only the middle section is cut out from this form of recording and used. As a result, the one-step nature of the key is preserved. However, in this code, the beginning of the numeric range is not zero. It is shifted by the specified value. During data processing, half the difference between the initial and reduced resolution is subtracted from the generated pulses.

Representation of a fractional number in fixed-point binary key

In the process of work, you have to operate not only with whole numbers, but also with fractions. Such numbers can be written using direct, reverse and complementary codes. The principle of constructing the mentioned keys is the same as that of integers. Until now, we believed that the binary comma should be to the right of the least significant digit. But that's not true. It can be located to the left of the most significant digit (in this case, only fractional numbers can be written as a variable), and in the middle of the variable (mixed values ​​can be written).

Binary floating point representation

This form is used to write or vice versa - very small. Examples include interstellar distances or the sizes of atoms and electrons. When calculating such values, one would have to use very large binary code. However, we do not need to take into account cosmic distances with millimeter precision. Therefore, the fixed-point notation form is ineffective in this case. An algebraic form is used to display such codes. That is, the number is written as a mantissa multiplied by ten to a power that reflects the desired order of the number. You should know that the mantissa should not be greater than one, and a zero should not be written after the decimal point.

Binary calculus is believed to have been invented in the early 18th century by German mathematician Gottfried Leibniz. However, as scientists recently discovered, long before the Polynesian island of Mangareva, this type of arithmetic was used. Despite the fact that colonization almost completely destroyed the original number systems, scientists have restored complex binary and decimal types of counting. Additionally, cognitive scientist Nunez claims that binary coding was used in ancient China as early as the 9th century BC. e. Other ancient civilizations, such as the Mayans, also used complex combinations of decimal and binary systems to track time intervals and astronomical phenomena.

A single digital signal is not very informative, because it can only take two values: zero and one. Therefore, in cases where it is necessary to transmit, process or store large amounts of information, several parallel digital signals are usually used. Moreover, all these signals should be considered only simultaneously; each of them separately does not make sense. In such cases, we talk about binary codes, that is, codes formed by digital (logical, binary) signals. Each of the logical signals included in the code is called a bit. The more bits included in the code, the more values ​​this code can take.

Unlike the decimal coding of numbers that is familiar to us, that is, a code with a base of ten, with binary coding, the base of the code is the number two (Fig. 2.9). That is, each code digit (each digit) of a binary code can take not ten values ​​(as in decimal code: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9), but only two - 0 and 1. The positional recording system remains the same, that is, the least significant digit is written on the right, and the most significant one on the left. But if in the decimal system the weight of each subsequent digit is ten times greater than the weight of the previous one, then in the binary system (with binary coding) it is twice as large. Each bit of binary code is called a bit (from the English "Binary Digit" - "binary number").

Rice. 2.9. Decimal and binary coding

In table Figure 2.3 shows the correspondence between the first twenty numbers in the decimal and binary systems.

The table shows that the required number of binary code bits is significantly greater than the required number of decimal code bits. The maximum possible number with the number of digits equal to three is 999 in the decimal system, and only 7 in the binary system (that is, 111 in binary code). In general, an n-bit binary number can take on 2n different values, and an n-bit decimal number can take on 10n different values. That is, writing large binary numbers (with more than ten digits) becomes not very convenient.

Table 2.3. Correspondence between numbers in decimal and binary systems
Decimal system Binary system Decimal system Binary system

In order to simplify the recording of binary numbers, the so-called hexadecimal system (hexadecimal coding) was proposed. In this case, all binary bits are divided into groups of four bits (starting with the least significant one), and then each group is encoded with one symbol. Each such group is called nibble(or nibble, notebook), and two groups (8 bits) - byte. From the table 2.3 shows that a 4-bit binary number can take on 16 different values ​​(from 0 to 15). Therefore, the required number of characters for a hexadecimal code is also 16, hence the name of the code. The first 10 characters are the numbers from 0 to 9, and then the 6 initial capital letters of the Latin alphabet are used: A, B, C, D, E, F.

Rice. 2.10. Binary and hexadecimal notation of numbers

In table 2.4 shows examples of hexadecimal encoding of the first 20 numbers (binary numbers are given in brackets), and Fig. Figure 2.10 shows an example of writing a binary number in hexadecimal form. To denote hexadecimal encoding, the letter "h" or "H" (from English Hexadecimal) is sometimes used at the end of a number, for example, the entry A17F h denotes the hexadecimal number A17F. Here A1 represents the high byte of the number and 7F is the low byte of the number. The entire number (in our case, a two-byte number) is called in a word.

Table 2.4. Hexadecimal coding system
Decimal system hexadecimal system Decimal system hexadecimal system
0 (0) A (1010)
1(1) B (1011)
2 (10) C (1100)
3 (11) D (1101)
4 (100) E (1110)
5 (101) F (1111)
6 (110) 10 (10000)
7 (111) 11 (10001)
8 (1000) 12 (10010)
9 (1001) 13 (10011)

To convert a hexadecimal number to a decimal number, you need to multiply the value of the lowest (zero) digit by one, the value of the next (first) digit by 16, the second digit by 256 (16 2), etc., and then add all the products. For example, take the number A17F:

A17F=F*16 0 + 7*16 1 + 1*16 2 + A*16 3 = 15*1 + 7*16+1*256+10*4096=41343

But every digital equipment specialist (developer, operator, repairman, programmer, etc.) needs to learn to handle hexadecimal and binary systems as freely as with regular decimal systems, so that no transfers from system to system are required.

In addition to the codes discussed, there is also the so-called binary-decimal representation of numbers. As in hexadecimal code, in BCD code each digit of the code corresponds to four binary digits, however, each group of four binary digits can take not sixteen, but only ten values, encoded by the characters 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. That is, one decimal place corresponds to four binary ones. As a result, it turns out that writing numbers in binary decimal code is no different from writing in ordinary decimal code (Table 2.6), but in reality it is just a special binary code, each digit of which can take only two values: 0 and 1. BCD code is sometimes very convenient for organizing decimal digital indicators and scoreboards.

Table 2.6. Binary decimal coding system
Decimal system Binary decimal system Decimal system Binary decimal system
0 (0) 10 (1000)
1(1) 11 (1001)
2 (10) 12 (10010)
3 (11) 13 (10011)
4 (100) 14 (10100)
5 (101) 15 (10101)
6 (110) 16 (10110)
7 (111) 17 (10111)
8 (1000) 18 (11000)
9 (1001) 19 (11001)

In binary code, you can perform any arithmetic operations on numbers: addition, subtraction, multiplication, division.

Consider, for example, adding two 4-bit binary numbers. Let us add the number 0111 (decimal 7) and 1011 (decimal 11). Adding these numbers is no more difficult than in decimal notation:

When adding 0 and 0 we get 0, when adding 1 and 0 we get 1, when adding 1 and 1 we get 0 and carry to the next digit 1. The result is 10010 (decimal 18). Adding any two n-bit binary numbers can result in an n-bit number or an (n+1)-bit number.

Subtraction is done in the same way. Let the number 0111 (7) be subtracted from the number 10010 (18). We write the numbers aligned to the least significant digit and subtract in the same way as in the case of the decimal system:

When subtracting 0 from 0 we get 0, when subtracting 0 from 1 we get 1, when subtracting 1 from 1 we get 0, when subtracting 1 from 0 we get 1 and borrow 1 in the next digit. The result is 1011 (decimal 11).

When subtracting, it is possible to obtain negative numbers, so you must use the binary representation of negative numbers.

To simultaneously represent both binary positive and binary negative numbers, the so-called two's complement code is most often used. Negative numbers in this code are expressed by a number that, when added to a positive number of the same value, will result in zero. In order to get a negative number, you need to change all the bits of the same positive number to the opposite ones (0 to 1, 1 to 0) and add 1 to the result. For example, write the number –5. The number 5 in binary code looks like 0101. We replace the bits with the opposite ones: 1010 and add one: 1011. We sum the result with the original number: 1011 + 0101 = 0000 (we ignore the transfer to the fifth digit).

Negative numbers in two's complement code are distinguished from positive numbers by the value of the most significant digit: a one in the most significant digit defines a negative number, and a zero defines a positive number.

In addition to standard arithmetic operations, the binary number system also uses some specific operations, for example, addition modulo 2. This operation (denoted by A) is bitwise, that is, there are no transfers from one digit to another and no borrowing in the highest digits. The rules for addition modulo 2 are as follows: , , . The same operation is called a function Exclusive OR. For example, let's sum modulo 2 two binary numbers 0111 and 1011:

Other bitwise operations on binary numbers include the AND function and the OR function. The AND function results in a one only if the corresponding bits of the two original numbers are both ones, otherwise the result is -0. The OR function results in one when at least one of the corresponding bits of the original numbers is 1, otherwise the result is 0.

The set of characters with which text is written is called alphabet.

The number of characters in the alphabet is its power.

Formula for determining the amount of information: N=2b,

where N is the power of the alphabet (number of characters),

b – number of bits (information weight of the symbol).

The alphabet with a capacity of 256 characters can accommodate almost all the necessary characters. This alphabet is called sufficient.

Because 256 = 2 8, then the weight of 1 character is 8 bits.

The unit of measurement 8 bits was given the name 1 byte:

1 byte = 8 bits.

The binary code of each character in computer text takes up 1 byte of memory.

How is text information represented in computer memory?

The convenience of byte-by-byte character encoding is obvious because a byte is the smallest addressable part of memory and, therefore, the processor can access each character separately when processing text. On the other hand, 256 characters is quite a sufficient number to represent a wide variety of symbolic information.

Now the question arises, which eight-bit binary code to assign to each character.

It is clear that this is a conditional matter; you can come up with many encoding methods.

All characters of the computer alphabet are numbered from 0 to 255. Each number corresponds to an eight-bit binary code from 00000000 to 11111111. This code is simply the serial number of the character in the binary number system.

A table in which all characters of the computer alphabet are assigned serial numbers is called an encoding table.

Different types of computers use different encoding tables.

The table has become the international standard for PCs ASCII(read aski) (American Standard Code for Information Interchange).

The ASCII code table is divided into two parts.

Only the first half of the table is the international standard, i.e. symbols with numbers from 0 (00000000), up to 127 (01111111).

ASCII encoding table structure

Serial number

Code

Symbol

0 - 31

00000000 - 00011111

Symbols with numbers from 0 to 31 are usually called control symbols.
Their function is to control the process of displaying text on the screen or printing, sounding a sound signal, marking up text, etc.

32 - 127

00100000 - 01111111

Standard part of the table (English). This includes lowercase and uppercase letters of the Latin alphabet, decimal numbers, punctuation marks, all kinds of brackets, commercial and other symbols.
Character 32 is a space, i.e. empty position in the text.
All others are reflected by certain signs.

128 - 255

10000000 - 11111111

Alternative part of the table (Russian).
The second half of the ASCII code table, called the code page (128 codes, starting from 10000000 and ending with 11111111), can have different options, each option has its own number.
The code page is primarily used to accommodate national alphabets other than Latin. In Russian national encodings, characters from the Russian alphabet are placed in this part of the table.

First half of the ASCII code table


Please note that in the encoding table, letters (uppercase and lowercase) are arranged in alphabetical order, and numbers are ordered in ascending order. This observance of lexicographic order in the arrangement of symbols is called the principle of sequential coding of the alphabet.

For letters of the Russian alphabet, the principle of sequential coding is also observed.

Second half of the ASCII code table


Unfortunately, there are currently five different Cyrillic encodings (KOI8-R, Windows. MS-DOS, Macintosh and ISO). Because of this, problems often arise with transferring Russian text from one computer to another, from one software system to another.

Chronologically, one of the first standards for encoding Russian letters on computers was KOI8 ("Information Exchange Code, 8-bit"). This encoding was used back in the 70s on computers of the ES computer series, and from the mid-80s it began to be used in the first Russified versions of the UNIX operating system.

From the early 90s, the time of dominance of the MS DOS operating system, the CP866 encoding remains ("CP" means "Code Page", "code page").

Apple computers running the Mac OS operating system use their own Mac encoding.

In addition, the International Standards Organization (ISO) has approved another encoding called ISO 8859-5 as a standard for the Russian language.

The most common encoding currently used is Microsoft Windows, abbreviated CP1251.

Since the late 90s, the problem of standardizing character encoding has been solved by the introduction of a new international standard called Unicode. This is a 16-bit encoding, i.e. it allocates 2 bytes of memory for each character. Of course, this increases the amount of memory occupied by 2 times. But such a code table allows the inclusion of up to 65536 characters. The complete specification of the Unicode standard includes all the existing, extinct and artificially created alphabets of the world, as well as many mathematical, musical, chemical and other symbols.

Let's try using an ASCII table to imagine what words will look like in the computer's memory.

Internal representation of words in computer memory

Sometimes it happens that a text consisting of letters of the Russian alphabet received from another computer cannot be read - some kind of “abracadabra” is visible on the monitor screen. This happens because computers use different character encodings for the Russian language.

Tool to make binary conversions. Binary code is a numeric system using base 2 used in informatics, symbols used in binary notation are generally zero and one (0 and 1).

Answers to Questions

You can edit this Q&A (add new info, improve translation, etc.) " itemscope="" itemtype="http://schema.org/Question">

How to convert a number in binary?

To convert a number to binary (with zeroes and ones) consists in a from base 10 to base 2 (natural binary code)

Example: 5 (base 10) = 1*2^2+0*2^1+1*2^0 = 101 (base 2)

The method consists in making successive divisions by 2 and noting the remainder (0 or 1 ) in the reverse order.

Example: 6/2 = 3 remains 0, then 3/2 = 1 remains 1, then 1/2 = 0 remains 1. The successive remainders are 0,1,1 so 6 is written 110 in binary.

You can edit this Q&A (add new info, improve translation, etc.) " itemscope="" itemtype="http://schema.org/Question">

How to convert a text to binary?

Associate with each letter of the alphabet a number, for example by using the code or the . This will replace each letter by a number that can then be converted to binary (see above).

Example: AZ is 65.90 () so 1000001.1011010 in binary

Similarly for binary to text translation, convert the binary to a number and then associate that number with a letter in the desired code.

You can edit this Q&A (add new info, improve translation, etc.) " itemscope="" itemtype="http://schema.org/Question">

How to translate binary

The binary does not directly translate, any number encoded in binary remains a number. On the other hand, it is common in computer science to use binary to store text, for example by using the table, which associates a number with a letter. An translator is available on dCode.

You can edit this Q&A (add new info, improve translation, etc.) " itemscope="" itemtype="http://schema.org/Question">

What is a bit?

A bit (contraction of binary digit) is a symbol in the binary notation: 0 or 1.

You can edit this Q&A (add new info, improve translation, etc.) " itemscope="" itemtype="http://schema.org/Question">

What is 1"s complement?

In informatics, one's complement is writing a number negatively inversing 0 and 1.

Example: 0111 becomes 1000, so 7 becomes -7

You can edit this Q&A (add new info, improve translation, etc.) " itemscope="" itemtype="http://schema.org/Question">

What is 2"s complement?

In informatics, one "s complement is writing a number negatively inversing 0 and 1 and adding 1.

Example: 0111 becomes 1001

Ask a new question

Source code

dCode retains ownership of the source code of the script Binary Code online. Except explicit open source license (indicated Creative Commons / free), any algorithm, applet, snippet, software (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, translator), or any function (convert, solve, decrypt , encrypt, decipher, cipher, decode, code, translate) written in any informatic language (PHP, Java, C#, Python, Javascript, Matlab, etc.) which dCode owns rights will not be released for free. To download the online Binary Code script for offline use on PC, iPhone or Android, ask for price quote on