Like binary code. Binary code to text

Computers don't understand words and numbers the way people do. Modern software allows the end user to ignore this, 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 format.

The binary system is based on two digits, 1 and 0, corresponding to 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 each number being ten times larger than the previous one. The binary system is similar, with each digit being twice as large as the previous one.

Counting in binary format

In binary expression, the first digit is equivalent to 1 in the decimal system. The second digit is 2, the third is 4, the fourth is 8, and so on - doubling each time. Adding all these values ​​will give you the number in decimal format.

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

Accounting for 0 gives us 16 possible values ​​for four binary bits. Move 8 bits and you get 256 possible values. This takes up a lot more space to represent since four decimal digits gives us 10,000 possible values. Of course, binary code takes up more space, but computers understand binary files much better than the decimal system. And for some things, like logic 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 operate in hexadecimal format, programmers use it to represent binary addresses in a human-readable format when writing code. This is because two digits of a hexadecimal number can represent an entire byte, meaning they replace eight digits in binary. The hexadecimal system uses the numbers 0-9, as well as the letters A through F, to create an additional six digits.

Why do computers use binary files?

Short answer: hardware and laws of physics. Every character in your computer is an electrical signal, and in the early days of computing, measuring electrical signals was much more difficult. It made more sense to distinguish only the "on" state, represented by a negative charge, and the "off" state, represented by a positive charge.

For those who don't know why "off" is represented by a positive charge, it is because electrons have a negative charge, and more electrons mean more current with a negative charge.

Thus, early room-sized computers used binary files to create their systems, and although they used older, bulkier equipment, they worked on the same fundamental principles. Modern computers use what is called transistor to perform calculations with binary code.

Here is a diagram of a typical transistor:

Essentially, it allows current to flow from the source to the drain if there is current in the gate. This forms a binary key. Manufacturers can make these transistors incredibly small—down to 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 (though this is due to their unrealistic molecular size being subject to the weirdness of quantum mechanics).

Why only binary system

So you might be thinking, “Why only 0 and 1? Why not add another number? Although this is partly due to the traditions of creating computers, at the same time, adding another digit would mean the need to distinguish another state of the current, not just “off” or “on”.

The problem here is that if you want to use multiple voltage levels, you need a way to easily perform calculations on them, and current hardware capable of this is not viable as a replacement for binary calculations. 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 not yet an effective replacement for the binary transistor, or at least no transistor on the same tiny scale as binary.

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

Thus, binary mathematics is easier for a 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 running on binary logic will have four possible outputs for each fundamental operation. But, since triple gates use three inputs, the triple truth table would have 9 or more. While the binary system has 16 possible operators (2^2^2), the ternary system would have 19683 (3^3^3). Scaling becomes an issue because while trinity is more efficient, it is also exponentially more complex.

Who knows? In the future, we may well see ternary computers as binary logic faces miniaturization challenges. For now, the world will continue to operate in binary mode.

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

How does a computer manage to process such a variety of information?
The secret lies in the binary number system. All data enters the computer, presented in the form of ones and zeros, each of which corresponds to one state of the electrical wire: ones - high voltage, zeros - low, or ones - the presence of voltage, zeros - its absence. Converting data into zeros and ones is called binary conversion, and its final designation is called binary code.
In decimal notation, based on the decimal number system used in everyday life, a numerical value is represented by ten digits from 0 to 9, and each place in the number has a value ten times higher than the place to the right of it. To represent a number greater than nine in the decimal system, a zero is placed in its place, and a one is placed in the next, more valuable place to the left. Similarly, in the binary system, which uses only two digits - 0 and 1, each place is twice as valuable as the place to the right of it. 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 up more space than in decimal. The alphabet can also be written in the binary system if a certain binary number is assigned to each letter.

Two figures 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 balls 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 types of balls in the binary system, an infinite number of combinations can be built simply by 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) represents 1 bit. A bit can be represented in other ways: the presence or absence of electric current, a hole or its absence, the direction of magnetization to the right or left. Eight bits make up a byte. 256 possible bytes can represent 256 characters and symbols. Many computers process one byte of data at a time.

Binary conversion. Four-digit binary code can represent decimal numbers from 0 to 15.

Code tables

When binary code is used to represent 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 American Standard Code for Information Interchange. The table on the right shows the ASCII codes for the English alphabet. Other codes are for thousands of characters and alphabets of other languages ​​of the world.

Part of an ASCII code table

Binary code represents text, computer processor instructions, or other data using any two-character system. Most commonly, it is a system of 0s and 1s that assigns a pattern of binary digits (bits) to each symbol and instruction. For example, a binary string of eight bits can represent any of 256 possible values ​​and can therefore generate many different elements. Reviews of binary code from the global professional community of programmers indicate that this is the basis of the profession and the main law of the functioning of computer systems and electronic devices.

Deciphering the binary code

In computing and telecommunications, binary codes are used for various methods of encoding data characters into bit strings. These methods can use fixed-width or variable-width strings. There are many character sets and encodings for converting to binary code. In fixed-width code, each letter, number, or other character is represented by a bit string of the same length. This bit string, interpreted as a binary number, is usually displayed in code tables in octal, decimal, or hexadecimal notation.

Binary Decoding: A bit string interpreted as a binary number can be converted to a decimal number. For example, the lowercase letter a, if represented by the bit string 01100001 (as in standard ASCII code), can also be represented as the decimal number 97. Converting binary code to text is the same procedure, just in reverse.

How it works

What does binary code consist of? The code used in digital computers is based on which there are only two possible states: on. and off, usually denoted by zero and one. While in the decimal system, which uses 10 digits, each position is a multiple of 10 (100, 1000, etc.), in the binary system, each digit position is a multiple of 2 (4, 8, 16, etc.). A binary code signal is a series of electrical pulses that represent numbers, symbols, and operations to be performed.

A device called a clock sends out regular pulses, and components such as transistors are turned on (1) or off (0) to transmit or block the pulses. In binary code, each decimal number (0-9) is represented by a set of four binary digits or bits. The four basic operations of arithmetic (addition, subtraction, multiplication, and division) can be reduced to combinations of fundamental Boolean algebraic operations on binary numbers.

A bit in communication and information theory is a unit of data equivalent to the result of a choice between two possible alternatives in the binary number system commonly used in digital computers.

Binary code reviews

The nature of code and data is a basic part of the fundamental world of IT. This tool is used by specialists from the global IT “behind the scenes” - programmers whose specialization is hidden from the attention of the average user. Reviews of binary code from developers indicate that this area requires a deep study of mathematical fundamentals and extensive practice in the field of mathematical analysis and programming.

Binary code is the simplest form of computer code or programming data. It is entirely represented by a binary digit system. According to reviews of binary code, it is often associated with machine code because binary sets can be combined to form source code that is interpreted by a computer or other hardware. This is partly true. uses sets of binary digits to form instructions.

Along with the most basic form of code, a binary file also represents the smallest amount of data that flows through all the complex, end-to-end hardware and software systems that process today's resources and data assets. The smallest amount of data is called a bit. The current strings of bits become code or data that is interpreted by the computer.

Binary number

In mathematics and digital electronics, a binary number is a number expressed in the base-2 number system, or binary numeric system, which uses only two characters: 0 (zero) and 1 (one).

The base-2 number system is a positional notation with a radius of 2. Each digit is referred to as a bit. Due to its simple implementation in digital electronic circuits using logical rules, the binary system is used by almost all modern computers and electronic devices.

Story

The modern binary number system as the basis for binary code was invented by Gottfried Leibniz in 1679 and presented in his article "Binary Arithmetic Explained". Binary numbers were central to Leibniz's theology. He believed that binary numbers symbolized the Christian idea of ​​creativity ex nihilo, or creation out of nothing. Leibniz tried to find a system that would transform verbal statements of logic into purely mathematical data.

Binary systems that predate Leibniz also existed in the ancient world. An example is the Chinese binary system I Ching, where the divination text is based on the duality of yin and yang. In Asia and Africa, slotted drums with binary tones were used to encode messages. The Indian scholar Pingala (circa 5th century BC) developed a binary system to describe prosody in his work Chandashutrema.

The inhabitants of the island of Mangareva in French Polynesia used a hybrid binary-decimal system until 1450. In the 11th century, the scientist and philosopher Shao Yong developed a method of organizing hexagrams that corresponds to the sequence 0 to 63, as represented in a binary format, with yin being 0 and yang being 1. The order is also a lexicographical order in blocks of elements selected from a two-element set.

New time

In 1605, discussed a system in which the letters of the alphabet could be reduced to sequences of binary digits, which could then be encoded as subtle variations of type in any random text. It is important to note that it was Francis Bacon who supplemented the general theory of binary coding with the observation that this method can be used with any objects.

Another mathematician and philosopher named George Boole published a paper in 1847 called “Mathematical Analysis of Logic,” which described the algebraic system of logic known today as Boolean algebra. The system was based on a binary approach, which consisted of three basic operations: AND, OR and NOT. This system did not become operational until an MIT graduate student named Claude Shannon noticed that the Boolean algebra he was learning was similar to an electrical circuit.

Shannon wrote a dissertation in 1937 that made important findings. Shannon's thesis became the starting point for the use of binary code in practical applications such as computers and electrical circuits.

Other forms of binary code

Bitstring is not the only type of binary code. A binary system in general is any system that allows only two options, such as a switch in an electronic system or a simple true or false test.

Braille is a type of binary code widely used by blind people to read and write by touch, named after its creator Louis Braille. This system consists of grids of six points each, three per column, in which each point has two states: raised or recessed. Different combinations of dots can represent all letters, numbers, and punctuation marks.

American Standard Code for Information Interchange (ASCII) uses a 7-bit binary code to represent text and other characters in computers, communications equipment, and other devices. Each letter or symbol is assigned a number from 0 to 127.

Binary coded decimal or BCD is a binary coded representation of integer values ​​that uses a 4-bit graph to encode decimal digits. Four binary bits can encode up to 16 different values.

In BCD-encoded numbers, only the first ten values ​​in each nibble are valid and encode the decimal digits with zeros after nines. The remaining six values ​​are invalid and may cause either a machine exception or unspecified behavior, depending on the computer's implementation of BCD arithmetic.

BCD arithmetic is sometimes preferred over floating point number formats in commercial and financial applications where complex number rounding behavior is undesirable.

Application

Most modern computers use a binary code program for instructions and data. CDs, DVDs, and Blu-ray Discs represent audio and video in binary form. Telephone calls are carried digitally in long-distance and mobile telephone networks using pulse code modulation and in voice over IP networks.

Here you can convert binary numbers to ASCII characters, which are often quite simple in your head.

1 - Convert every 4 binary digits to one sixth digit.

Here's a conversion chart in binary format:

0001 = 1 0010 = 2 0011 = 3 0100 = 4 0101 = 5 0110 = 6 0111 = 7 1000 = 8 1001 = 9 1010 = a (the hex number a, not the letter a) 1011 = b 1100 = c 1101 = d 1110 = e 1111 = f

(The hexadecimal numbers a through f are the decimal numbers 10 through 15. What hexadecimal, or "base 16" is, is that instead of each digit being capable of representing 10 different numbers, such as decimal or "base 10", each digit is instead this can represent 16 different numbers.)

Once you know this diagram, converting any string of binary digits to a string of hexadecimal digits is simple.

For example,

01000100 = 0100 0100 = 44 hex 1010001001110011 = 1010 0010 0111 0011 = a273 hex

Simple enough, right? Easily convert a binary number of any length to its hexadecimal equivalent.

(This works because hexadecimal is base 16 and binary is base 2, and 16 is the 4th power of 2, so it takes 4 binary digits to get 1 hex digit. 10, on the other hand, is not a power of 2, so we don't we can convert binary to decimal almost as easily.)

2 - Divide the string of hexadecimal digits into pairs.

When converting a number to ASCII, every two hexadecimal digits are characters. Thus, split the hexadecimal string into two digits.

You would divide a hexadecimal number like 7340298b392 into 6 pairs, like this:

7340298b392 = 07 34 02 98 b3 92

These are 6 pairs of hexadecimal digits, so there will be 6 letters. (Except that I immediately realized that 98, b3 and 92 are not letters. I'll explain why in a minute.)

3 - Convert each pair of hexadecimal digits to a decimal number.

Do this by multiplying (the decimal equivalent) of the left digit by 16 and adding the second one.

For example, b3 hex = 11 * 16 + 3, which is equal to 110 + 66 + 3, which is 179. (b hex is equal to 11 decimals.)

4 - Convert decimal numbers to ASCII characters.

Now, to get the ASCII letters for decimal numbers, just keep in mind that in ASCII, 65 is an uppercase "A" and 97 is a lowercase "a".

So, what is the letter 68?

68 - 4th letter of the alphabet in upper case, on the right?
65 = A, 66 = B, 67 = C, 68 = D.

So 68 is D.

You take the decimal number, subtract 64 for uppercase letters if the number is less than 97 or 96 for lowercase letters if the number is 97 or greater, and the number of letters of the alphabet associated with that set are 2 hexadecimal digits.

Alternatively, if you're not afraid of a little simple hex arithmetic, you can skip step 3 and just go from hex to ASCII, remembering e.g.

Hex 41 = "A" hex 61 = "a"

So, subtract 40 hex for uppercase letters or 60 hex for lowercase letters and convert what's left to decimal to get the letter number of the alphabet.

For example

01101100 = 6c, 6c - 60 = c = 12 decimal = "l" 01010010 = 52, 52 - 40 = 12 hex = 18 decimal = "R"

(It's useful to remember, though, that "m" (or "M") is the 13th letter of the alphabet. So you can count up or down from 13 to find a letter that's closer to the middle than to either end.)

I saw this on a shirt once and was able to read it in my head:

01000100 01000001 01000100

I did it like this:

01000100 = 0100 0100 = 44 hex, - 40 hex = ucase letter 4 = D 01000001 = 0100 0001 = 41 hex, - 40 hex = ucase letter 1 = A 01000100 = 0100 0100 = 44 hex, - 40 hex = ucase letter 4 = D

The shirt said "DAD", which I thought was cool since it was being purchased by a pregnant woman. Her husband must be like me.

How did I immediately understand that 92, b3 and 98 were not letters?

Because the ASCII code for lowercase "z" is 96 + 26 = 122, which in hexadecimal is 7a. 7a is the largest hexadecimal number for a letter. Anything greater than 7a is not a letter.

So how can you do this as a human being.

How do computer programs do this?

For each set of 8 binary digits, convert it to a number and look it up in an ASCII table.

(This is a fairly obvious and straightforward way. A typical programmer could think of 10 or 15 other ways within a few minutes. The details depend on the computer's language interface environment.)

The meaning of the term “binary” is that it consists of two parts or components. Thus, binary codes are codes that consist of only two symbolic states, such as black or white, light or dark, conductor or insulator. A binary code in digital technology is a way of representing data (numbers, words, and others) as a combination of two characters, which can be designated as 0 and 1. The characters or units of BC are called bits. One of the justifications for the use of BC is the simplicity and reliability of storing information in any medium in the form of a combination of just two of its physical states, for example, in the form of a change or constancy of the light flux when reading from an optical code disk.
There are various possibilities for encoding information.

Binary code

In digital technology, a method of representing data (numbers, words, and others) as a combination of two characters, which can be designated as 0 and 1. The signs or units of the DC are called bits.

One of the justifications for the use of DC is the simplicity and reliability of storing information in any medium in the form of a combination of just two of its physical states, for example, in the form of a change or constancy of the magnetic flux in a given cell of the magnetic recording medium.

The largest number that can be expressed in binary depends on the number of digits used, i.e. on the number of bits in the combination expressing the number. For example, to express the numeric values ​​from 0 to 7, it is enough to have a 3-digit or 3-bit code:

numeric value binary code
0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111

From this we can see that for a number greater than 7 with a 3-digit code there are no longer code combinations of 0 and 1.

Moving from numbers to physical quantities, let us formulate the above statement in a more general form: the largest number of values ​​m of any quantity (temperature, voltage, current, etc.), which can be expressed in binary code, depends on the number of bits used n as m= 2n. If n=3, as in the example considered, then we get 8 values, including leading 0.
Binary code is a multi-step code. This means that when moving from one position (value) to another, several bits can change simultaneously. For example, the number 3 in binary code = 011. The number 4 in binary code = 100. Accordingly, when moving from 3 to 4, all 3 bits change their state to the opposite simultaneously. Reading such a code from a code disk would lead to the fact that, due to inevitable deviations (tolerances) during the production of a code disk, a change in information from each of the tracks separately will never occur simultaneously. This in turn would lead to the fact that when moving from one number to another, incorrect information would be briefly given. So, during the above-mentioned transition from the number 3 to the number 4, a short-term output of the number 7 is very likely when, for example, the most significant bit during the transition changed its value a little earlier than the rest. To avoid this, a so-called one-step code is used, for example the so-called Gray Code.

Gray code

Gray code is a so-called one-step code, i.e. When moving from one number to another, only one of all bits of information always changes. An error when reading information from a mechanical code disk when moving from one number to another will only lead to the fact that the transition from one position to another will be only slightly shifted in time, but the issuance of a completely incorrect angular position value when moving from one position to another is completely eliminated .
Another advantage of Gray Code is its ability to mirror information. So, by inverting the most significant bit, you can simply change the direction of counting and thus match the actual (physical) direction of rotation of the axis. Changing the counting direction in this way can be easily changed by controlling the so-called “Complement” input. The output value can thus be increasing or decreasing for the same physical direction of rotation of the axis.
Since the information expressed in Gray Code is purely encoded in nature and does not carry real numerical information, it must first be converted into a standard binary code before further processing. This is done using a code converter (Gray-Binar decoder), which, fortunately, is easily implemented using a circuit of exclusive-or (XOR) logic elements, both in software and in hardware.

Corresponding decimal numbers in the range from 0 to 15 to binary and Gray codes

Binary coding Gray coding
Decimal code
Binary value Sixteen meaning Decimal code Binary value Sixteen meaning
0 0000 0h 0 0000 0h
1 0001 1h 1 0001 1h
2 0010 2h 3 0011 3h
3 0011 3h 2 0010 2h
4 0100 4h 6 0110 6h
5 0101 5h 7 0111 7h
6 0110 6h 5 0101 5h
7 0111 7h 4 0100 4h
8 1000 8h 12 1100 Ch
9 1001 9h 13 1101 Dh
10 1010 Ah 15 1111 Fh
11 1011 Bh 14 1110 Eh
12 1100 Ch 10 1010 Ah
13 1101 Dh 11 1011 Bh
14 1110 Eh 9 1001 9h
15 1111 Fh 8 1000 8h

Converting the Gray code to the usual binary code can be done using a simple circuit with inverters and exclusive-or gates as shown below:

Code Gray-Excess

The usual one-step Gray code is suitable for resolutions that can be represented as a number raised to the power of 2. In cases where it is necessary to implement other permissions, the middle section is cut out from the regular Gray code and used. This way the code remains “one-step”. However, the numeric range does not start at zero, but is shifted by a certain value. When processing information, half the difference between the original and reduced resolution is subtracted from the generated signal. Resolutions such as 360? to express an angle are often implemented by this method. So a 9-bit Gray code equal to 512 steps, trimmed on both sides by 76 steps, will be equal to 360°.