ComputersProgramming

Binary code. Types and length of the binary code. Reverse binary code

A binary code is a form of recording information in the form of units and zeros. Such a calculus system is positional with base 2. To date, the binary code (the table presented below, contains some examples of writing numbers) is used in all digital devices without exception. Its popularity is due to the high reliability and simplicity of this form of recording. Binary arithmetic is very simple, accordingly, it is easy to implement and at the hardware level. Digital electronic components (or as they are also called - logical) are very reliable, since they operate in operation with only two states: a logical unit (there is a current) and a logic zero (there is no current). Thus, they favorably differ from analog components, the work of which is based on transient processes.

How is the binary form of the record formed?

Let's see how this key is formed. A single bit of binary code can contain only two states: zero and one (0 and 1). When two digits are used, it is possible to write four values: 00, 01, 10, 11. The three-digit record contains eight states: 000, 001 ... 110, 111. As a result, the length of the binary code depends on the number of digits. 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, these keys are used to record a variety of processed information. The bit depth of the binary code can significantly exceed the bit depth of the processor and its built-in memory. In such cases, long numbers occupy several memory cells and are processed using several instructions. In this case, all sectors of memory that are allocated to a multibyte binary code are treated as one number. Depending on the need to provide this or that information, the following types of keys are distinguished:

  • Unsigned;
  • Direct whole character codes;
  • Signed backward;
  • Signed additional;
  • Gray code;
  • Gray-Express code .;
  • Fractional codes.

Let us consider in more detail each of them.

Unsigned binary code

Let's see what kind of record this is. In whole unsigned 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 express such a binary code. Let's consider the possibilities of this form of recording. If you use this type of an unsigned key consisting of eight digits, the range of possible numbers will be from 0 to 255. The sixteen digit 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 neighboring destinations . Special commands provide the work with such keys.

Direct integer sign codes

In this kind of binary key, the most significant bit is used to write the sign of a number. A zero corresponds to a plus, and a one corresponds to a minus sign. As a result of introducing this digit, the range of coded numbers is shifted to the negative side. It turns out that an eight-digit signed whole binary key can write numbers in the range from -127 to +127. Sixteen-digit - in the range from -32767 to +32767. In eight-bit microprocessors, two adjacent sectors are used to store such codes.

The disadvantage of this form of writing is that the key and digital digits of the key need to be processed separately. Algorithms for programs that work with these codes are very complex. To change and allocate signed digits, you must use the masking mechanisms of this symbol, which contributes to a sharp increase in the size of the software and reduce its performance. In order to eliminate this drawback, a new kind of key was introduced-an inverse binary code.

Signed reverse key

This form of recording differs from direct codes only in that a negative number in it is obtained by inverting all bits of the key. At the same time, digital and signed digits are identical. Thanks to this, the algorithms for working with this kind of codes are greatly simplified. However, the reverse key requires a special algorithm for recognizing the first digit, calculating the absolute value of the number. And also the restoration of the sign of the resulting value. Moreover, in the inverse and forward codes of the number for writing zero, use two keys. Despite the fact that this value does not have a positive or negative sign.

Signed additional binary number code

This type of record does not have the listed shortcomings of the previous keys. Such codes allow direct summation of both positive and negative numbers. At the same time, an analysis of the sign discharge is not carried out. All this became possible due to the fact that additional numbers represent a natural ring of symbols, rather than artificial entities, such as direct and reverse keys. Moreover, an important factor is that it is extremely simple to calculate the additions in binary codes. For this it is sufficient to add one to the back key. If you use this kind of character code consisting of eight digits, the range of possible numbers will be from -128 to +127. The sixteen digit key will have a range from -32768 to +32767. In eight-bit processors, two adjacent sectors are also used to store such numbers.

The binary additional code is interesting by the observed effect, which is called the phenomenon of the spread of the sign. Let's see what that means. This effect consists in the fact that during the conversion of a single-byte value to a double-byte one, each bit of the high-order byte should be assigned the values of the sign bits of the least significant byte. It turns out, that for storage of a character character of number it is possible to use the senior bits. In this case, the value of the key does not change at all.

Gray Code

This form of record, in fact, is a one-step key. That is, during the transition from one value to another, only one bit of information changes. In this case, the error in reading data leads to a transition from one position to another with a slight time shift. However, obtaining a completely wrong result of the angular position in such a process is completely eliminated. The advantage of this code is its ability to mirror information. For example, by inverting the high-order bits, you can simply change the direction of the count. This is due to the control input Complement. In this case, the output value can be either increasing or decreasing at one physical axis rotation direction. Since the information recorded in Gray's key has an exclusively coded character that does not carry real numeric data, it is necessary beforehand to convert it into a normal binary record form before further work. This is done using a special converter - the Gray-Binar decoder. This device is easily implemented on elementary logic elements both hardware and software.

Gray-Express code

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

Representation of a fractional number in a binary key with a fixed comma

In the process of work, it is necessary to operate not only in whole numbers, but also in fractional. Such numbers can be written using direct, inverse and additional codes. The principle of constructing the mentioned keys is the same as for the whole keys. Until now, we believed that the binary comma should be to the right of the lower order. But this is not so. It can be placed to the left of the highest digit (in this case, only fractional numbers can be written as a variable), and in the middle of a variable (mixed values can be written).

Floating point binary floating point representation

This form is used to write large numbers, or vice versa - very small. An example is the interstellar distance or the size of atoms and electrons. When calculating such values, we would have to use a binary code with a very large bit width. However, we do not need to take into account the cosmic distance to within a millimeter. Therefore, the form of recording with a fixed comma is ineffective in this case. To display such codes an algebraic form is used. 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 more than one, and after the comma, zero should not be recorded.

It is interesting

It is believed that the binary calculus was invented in the early 18th century by a mathematician from Germany Gottfried Leibniz. However, as scientists recently discovered, long before this, the aborigines of the Polynesian island of Mangarev used this kind of arithmetic. Despite the fact that the colonization has almost completely destroyed the original calculus systems, scientists have restored complex binary and decimal types of accounts. In addition, the scientist Cognitivist Nunez argues that binary coding was used in ancient China as far back as the 9th century BC. E. Other ancient civilizations, for example, the Maya Indians, also used complex combinations of decimal and binary systems to track time intervals and astronomical phenomena.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.atomiyme.com. Theme powered by WordPress.