Convert binary. Binary codes. Internal representation of words in computer memory


Greek Georgian
Ethiopian
Jewish
Akshara-sankhya Other Babylonian
Egyptian
Etruscan
Roman
Danube Attic
Kipu
Mayan
Aegean
KPPU symbols Positional , , , , , , , , , , Nonga-positional Symmetrical Mixed systems Fibonaccieva Non-positional Single (unary)

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

Binary notation of numbers

In the binary system, numbers are written using two characters ( 0 and 1 ). In order not to be confused in which number system the number is written, it is supplied with an indicator at the bottom right. For example, a decimal number 5 10 , in binary 101 2 ... Sometimes a binary number is indicated by the prefix 0b or symbol & (ampersand), for example 0b101 or respectively &101 .

In the binary number system (as in other number systems other than decimal), the characters are read one at a time. For example, the number 101 2 is pronounced "one zero one".

Integers

A natural number written in binary 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:

(an - 1 an - 2… a 1 a 0) 2 = ∑ k = 0 n - 1 ak 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: a "-" sign in front of the number. Namely, a negative binary integer (- 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 as (an - 1 an - 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:

(an - 1 an - 2… a 1 a 0, a - 1 a - 2… a - (m - 1) a - m) 2 = ∑ k = - mn - 1 ak 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),)

Addition, subtraction and multiplication of binary numbers

Addition table

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

An example of multiplication "column" (decimal expression 14 10 * 5 10 = 70 10 in binary looks like 1110 2 * 101 2 = 1000 110 2):

Starting with the number 1, all numbers are multiplied by two. The point after 1 is called a binary point.

Converting binary numbers to decimal

Let's say a binary number is given 110001 2 ... To convert to decimal, write it down as a digit sum as follows:

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

The same thing is slightly different:

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

You can write it down in the form of a table as follows:

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 up the resulting decimal numbers. Thus, the binary number 110001 2 is equivalent to decimal 49 10.

Converting fractional binary numbers to decimal

Need to translate 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

The same thing is slightly different:

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

Horner transformation

In order to convert numbers from binary to decimal system using this method, it is necessary 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. The reverse operation is difficult, since it requires skills in addition and multiplication in the binary number system.

For example, the binary number 1011011 2 translated into decimal system like this:

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.

Translation of the fractional part of numbers by Horner's method

The numbers are taken from the number from right to left and divided by the base of the number system (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 to the end of the binary notation. We continue dividing until the quotient is 0. Write the result from right to left. That is, the bottom digit (1) will be the leftmost, and so on. As a result, we get the number 19 in binary notation: 10011 .

Convert fractional decimal numbers to binary

If there is an integer part in the original number, then it is converted separately from the fractional part. The conversion of a fractional number from the decimal number system to binary is carried out according to the following algorithm:

  • The fraction is multiplied by the base binary system numbers (2);
  • In the resulting product, the integer part is highlighted, which is taken as the most significant bit 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 computational accuracy is achieved. Otherwise, calculations continue over the fractional part of the product.

Example: You want to translate a fractional decimal number 206,116 to a binary fraction.

Translation of the whole part gives 206 10 = 11001110 2 according to the previously described algorithms. The fractional part of 0.116 is multiplied by the base 2, putting the whole parts of the product in the digits after the decimal point of the sought binary fractional 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, since it is the simplest and meets the requirements:

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

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

In the English system of measures

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

Generalizations

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

History

  • A complete set of 8 trigrams and 64 hexagrams, an analogue of 3-bit and 6-bit numbers, was known in ancient China in the classical texts of the Book of Changes. 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 of obtaining them was developed by the Chinese scientist and philosopher Shao Yun in the 11th century. However, there is no evidence that Shao Yong understood the rules of binary arithmetic by arranging two-character tuples in lexicographic order.
  • Sets, which are combinations of binary numbers, were used by Africans in traditional divination (such as Ifa) along with medieval geomancy.
  • In 1854, the English mathematician George Boole published a landmark work 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 presented 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 Stiebitz, who later worked at Bell Labs, created a Model K computer based on the relay. K itchen ”, the kitchen where the assembly was done), which performed binary addition. In late 1938, Bell Labs launched a research program led by Stibitz. 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, Stiebitz demonstrated the ability to send commands to a remote complex number calculator over a telephone line using a teletypewriter. This was the first attempt to use a remote computer via a telephone line. Among the conference participants who witnessed the demonstration were John von Neumann, John Mauchly and Norbert Wiener, who later wrote about it in their memoirs.
  • On the pediment of the building (the former Computing Center of the Siberian Branch of the USSR Academy of Sciences) in the Novosibirsk Academgorodok, there is a binary number 1000110, equal to 70 10, which symbolizes the date of the building's construction (

Computers don't understand words and numbers the way humans do. Modern software allows the end user to ignore it, but at the lowest levels your computer operates on a binary electrical signal that has only two states: whether there is current or not. To "understand" complex data, your computer must encode it in binary.

The binary system is based on two digits, 1 and 0, which correspond to the on and off states that your computer can understand. You are probably familiar with the decimal system. It uses ten digits, from 0 to 9, and then moves on to the next order to form two-digit numbers, with a digit from each next order ten times larger than the previous one. The binary system is similar, with each digit twice as large as the previous one.

Counting in binary

In binary, the first digit is the decimal 1. The second digit is 2, the third is 4, the fourth is 8, and so on - it doubles each time. Adding all of these values ​​will give you a decimal number.

1111 (binary) = 8 + 4 + 2 + 1 = 15 (decimal)

Accounting 0 gives us 16 possible values ​​for four binary bits. Move 8 bits and you get 256 possible values. This takes a lot more space to represent, since four digits in decimal give us 10,000 possible values. Of course, binary code takes up more space, but computers understand binaries much better than the decimal system. And for some things, like logical processing, binary is better than decimal.

It should be said that there is another basic system that is used in programming: hexadecimal... Although computers do not work in hexadecimal format, programmers use it to represent binary addresses in human readable format when they write code. This is because two digits of a hexadecimal number can represent a whole byte, that is, they replace eight digits in binary. The hexadecimal system uses the numbers 0-9 and the letters A through F to give an additional six digits.

Why computers use binaries

The short answer is: Hardware and the laws of physics. Every character on your computer is an electrical signal, and in the early days of computing, electrical signals were much more difficult to measure. It was more reasonable to distinguish between only the “on” state, represented by a negative charge, and the “off” state, represented by a positive charge.

For those who do not know why "off" is represented by a positive charge, this is due to the fact that electrons have a negative charge, and more electrons - more current with a negative charge.

Thus, early room-sized computers used binaries to build their systems, and although they used older, more cumbersome hardware, they operated on the same fundamental principles. Modern computers use the so-called transistor to perform calculations with binary code.

Here is a diagram of a typical transistor:

Essentially, it allows current to flow from source to drain if there is current in the gate. This forms a binary key. Manufacturers can make these transistors incredibly small - as small as 5 nanometers or the size of two strands of DNA. This is how modern processors work, and even they can suffer from problems distinguishing between on and off states (although this is due to their unrealistic molecular size, subject to oddities of quantum mechanics).

Why only binary system

So you might be thinking, “Why only 0 and 1? Why not add one more number? " While this is partly due to the tradition of making computers, adding another digit would mean that there is another state of current to be highlighted, not just off or on.

The problem here is that if you want to use multiple voltage levels, you need a way to easily compute with them, and modern hardware capable of doing this is not viable as a replacement for binary computation. For example, there is a so-called triple computer developed in the 1950s, but development stopped there. Ternary logic more efficient than binary, but there is still no effective replacement for binary transistor, or at least there is no transistor as tiny in scale as binary.

The reason why we cannot use triple logic comes down to how transistors are connected in a computer and how they are used for mathematical calculations. The transistor receives information on two inputs, performs an operation and returns the result to one output.

Thus, binary mathematics is easier on the computer than anything else. Binary logic is easily converted to binary systems, with True and False corresponding to On and Off states.

A binary truth table operating on binary logic will have four possible outputs for each fundamental operation. But, since the triple gate uses three entrances, the triple truth table would have 9 or more. While the binary system has 16 possible operators (2 ^ 2 ^ 2), ternary system would have 19683 (3 ^ 3 ^ 3). Scaling becomes an issue because, while ternary is more efficient, it is also exponentially more complex.

Who knows? In the future, it is quite possible that we will see trigeminal computers, since binary logic faced problems of miniaturization. For now, the world will continue to operate in binary mode.

Binary code- this is the presentation of information by combining the symbols 0 or 1. Sometimes it is very difficult to understand the principle of encoding information in the form of these two numbers, but we will try to explain everything in detail.

By the way, on our site you can translate any text into decimal, hexadecimal, binary code using the Online Code Calculator.

When we see something for the first time, we often ask the logical question of how it works. Any new information is perceived by us as something complex or created exclusively for viewing from afar, however, for people who want to learn more about binary code, a simple truth is revealed - the binary code is not at all difficult to understand, as it seems to us. For example, the English letter T in binary system will take the following form - 01010100, E - 01000101 and the letter X - 01011000. Based on this, we understand that the English word TEXT in the form of a binary code will look like this: 01010100 01000101 01011000 01010100. The computer understands just such a representation of characters for a given word, well, we prefer to see it in the presentation of the letters of the alphabet.

Today binary code it is actively used in programming, since computers work precisely because of it. But programming hasn't boiled down to an endless array of ones and zeros. Since this is a rather laborious process, measures have been taken to simplify understanding between a computer and a person. The solution to the problem was the creation of programming languages ​​(BASIC, C ++, etc.). As a result, the programmer writes the program in a language that he understands, and then the compiler program translates everything into machine code, starting the computer.

Converting a natural number from a decimal number system to a binary system.

To convert numbers from decimal to binary, use the "replacement algorithm", which consists of the following sequence of actions:

1. Choose the desired number and divide it by 2. If the result of division is with a remainder, then the number of the binary code will be 1, if there is no remainder - 0.

2. Discarding the remainder, if any, again divide the number obtained as a result of the first division by 2. Set the number of the binary system depending on the presence of the remainder.

3. We continue to divide, calculating the number of the binary system from the remainder, until we reach the number that cannot be divided - 0.

4. At this point, the binary code is considered ready.

For example, let's convert the number 7 to the binary system:

1.7: 2 = 3.5. Since there is a remainder, we write the first number of the binary code 1.

2.3: 2 = 1.5. We repeat the procedure with the choice of the number of the code between 1 and 0, depending on the remainder.

3.1: 2 = 0.5. Select 1 again following the same principle.

4. As a result, we get, converted from decimal to binary, the code - 111.

An infinite number of numbers can be translated this way. Now let's try to do the opposite - convert a number from binary to decimal.

Binary to decimal number conversion.

To do this, we need to number our binary number 111 from the end, starting with zero. For 111, that's 1 ^ 2 1 ^ 1 1 ^ 0. Based on this, the number for the number will serve as its power. Next, we perform actions according to the formula: (x * 2 ^ y) + (x * 2 ^ y) + (x * 2 ^ y), where x is the ordinal number of the binary code, and y is the degree of this number. Substitute our binary number under this formula and calculate the result. We get: (1 * 2 ^ 2) + (1 * 2 ^ 1) + (1 * 2 ^ 0) = 4 + 2 + 1 = 7.

A bit of the history of the binary number system.

It is generally accepted that for the first time binary system proposed by Gottfried Wilhelm Leibniz, who considered the system useful in complex mathematical calculations and science. But according to some sources, before his proposal for a binary number system, a wall inscription appeared in China, which was deciphered when using binary code... Long and short sticks were depicted on the inscription. Assuming that the long stick is 1 and the short stick is 0, there is a chance that the idea of ​​a binary code existed in China many years before its official discovery. Deciphering the code identified only a prime natural number there, but this is a fact that remains to them.

Since it is the most simple and meets the requirements:

  • The fewer values ​​exist in the system, the easier it is to manufacture individual elements operating with these values. In particular, two digits of the binary number system can be easily represented by many physical phenomena: there is a current - there is no current, the magnetic field induction is greater than the threshold value or not, etc.
  • The fewer the number of states an element has, the higher the noise immunity and the faster it can work. For example, to encode three states through the magnitude of the magnetic field induction, you will need to enter two threshold values, which will not contribute to noise immunity and reliability of information storage.
  • Binary arithmetic is pretty straightforward. The tables of addition and multiplication, the basic operations on numbers, are simple.
  • It is possible to use the apparatus of logic algebra to perform bitwise operations on numbers.

Links

  • Online calculator for converting numbers from one number system to another

Wikimedia Foundation. 2010.

See what "Binary Code" is in other dictionaries:

    2 bit Gray code 00 01 11 10 3 bit Gray code 000 001 011 010 110 111 101 100 4 bit Gray code 0000 0001 0011 0010 0110 0111 0101 0100 1100 1101 1111 1110 1010 1011 1001 1000 Gray code is a number system in which two adjacent values ... ... Wikipedia

    Signal Point Code (SPC) of signal system 7 (SS7, OKS 7) is unique (in home network) node address used at the third level of MTP (routing) in telecommunication SS7 networks for identification ... Wikipedia

    In mathematics, squarefree is a number that is not divisible by any square except 1. For example, 10 is squarefree, but 18 is not, since 18 is divisible by 9 = 32. The beginning of a sequence of squarefree numbers is: 1, 2, 3, 5, 6, 7, ... ... Wikipedia

    To improve this article, is it desirable ?: Wikify the article. Redesign the design in accordance with the rules for writing articles. Correct the article according to the stylistic rules of Wikipedia ... Wikipedia

    This term has other meanings, see Python (disambiguation). Python Language class: mu… Wikipedia

    In the narrow sense of the word, at present, the phrase means "Attempt on the security system", and tends more towards the meaning of the next term Cracker attack. This happened due to the distortion of the meaning of the word "hacker". Hacker ... ... Wikipedia