Logical element excluding or. Logical operators VBA logical operation excluding or

Often, in order to demonstrate the limited capabilities of single-layer perceptrons when solving problems, it is resorted to the consideration of the so-called problem. Xor - exclusive or.

The essence of the task is to be as follows. The logical function XOR is excluding or. This function is from two arguments, each of which can be zero or unit. It takes a value when one of the arguments is equal to one, but not both, otherwise. The problem can be illustrated using a single-layer single-stage system with two inputs shown in the figure below.

Denote one input through, and the other through, then all their possible combinations will consist of four points on the plane. The table below shows the required link between the inputs and the output, where the input combinations that should give zero output are labeled and, a single output - and.

Points Value Value Required output
0 0 0
1 0 1
0 1 1
1 1 0

One neuron with two inputs can form a decisive surface in the form of an arbitrary straight line. In order for the network to implement the XOR function, the specified table above, you need to position the direct so that the points be on one side of the straight, and the point is on the other. Having tried to draw such a straight line in the figure below, we make sure it is impossible. This means that whatever values \u200b\u200bare attributed to the scales and threshold, a single-layer neural network is unable to reproduce the ratio between the input and output required to represent the XOR function.

However, the XOR function is easily formed by a two-layer network, and in many ways. Consider one of these ways. We upgrade the network in the figure, adding another hidden layer of neurons:

Note that this network is given as it is, i.e. We can assume that it is already trained. The numbers above the arrows show the values \u200b\u200bof synaptic scales. As an activation function, we will apply the function of a single jump with a threshold having the following chart:

Then the result of the operation of such a neural network can be represented as the following table:

Points Value Value Required output
0 0 0 0 0 0
1 0 1 1 0 1
0 1 1 0 1 1
1 1 0 0 0 0

Each of the two neurons of the first layer forms a decisive surface in the form of an arbitrary straight line (divides the plane into two half-planes), and the neuron of the output layer combines these two solutions, forming a decisive surface in the form of a strip formed by parallel straight neurons of the first layer:

The neural network used in this article to solve the XOR task is primitive and does not use all the capabilities of multi-layer networks. It is obvious that multilayer neural networks have a greater representing capacity than single-layer, only in the case of the presence of nonlinearity. And in this network, a threshold linear activation function is applied. Such a network cannot be trained, for example, by applying an error inversely distribution algorithm.

The function performed by them is somewhat more complicated than in the case of an item and or element or. All element inputs excluding or equal, but none of the inputs can block other inputs by setting the output signal to the unit or zero level. Table 4.1. Tank truth two-way elements of excluding or
Login 1. Login 2. Output
0 0 0
0 1 1
1 0 1
1 1 0


Fig. 4.1.

Under the function, excluding or refers to the following: The unit at the output appears when only one input is present. If the units on the inputs are two or more, or if at all the inputs of zero, then the output will be zero. Tank truth The two-time element is excluding or given in Table. 4.1. Designations adopted in domestic and foreign circuits are shown in Fig. 4.1. The inscription on the domestic designation of the element is excluding or "\u003d 1" just indicates that the situation is distinguished when one and only one unit is on the inputs.

Elements excluding or in standard series a bit. The domestic series offer LP5 chips (four two-axis elements with 2C output), LL3 and LP12, differ from LP5 OK output. Too specific function is implemented by these elements.

From the point of view of mathematics, the element excluding or performs the operation of the so-called summation of module 2. Therefore, these elements are also called the adders in the module two. As already noted in the previous lecture, the summation of module 2 is a plus sign enclosed in a circle.

The main use of elements excluding or, directly the following tatasets of truthIt consists in comparing two input signals. In the case when two units or two zero come to the inputs (signals coincide), zero is formed at the output (see Table 4.1). Usually, with this application, a permanent level is supplied to one element input, with which the time-changing signal comes to another input. But significantly more often for comparison of signals and codes apply special chips comparators Codovwhich will be discussed in the next lecture.

As an adder module 2, the element is excluding or used in parallel and consecutive divisors for module 2, which serve to calculate cyclic checks. But these schemes will be discussed in detail in lectures 14.15.

Important use of elements excluding or is a managed inverter (Fig. 4.2). In this case, one of the element inputs is used as a manager, and an information signal comes to another element. If the unit is input, then the input signal is inverted if zero is not inverted. Most often control signal Set by a constant level by defining the mode of the element, and the information signal is pulsed. That is, an element excluding or can change the polarity of the input signal or front, and may not be changed depending on control signal.


Fig. 4.2.

In the case when there are two signals of the same polarity (positive or negative), and at the same time their simultaneous arrival is excluded, the element is excluding or can be used to mix these signals (Fig. 4.3). With any polarity of the input signals, the output signals of the element will be positive. With positive input signals, the element excluding or will operate as an element 2, and with negative it will replace the element 2I - not. Such replacements may be useful in cases where some elements excluding or are left in the diagram. True, it should be borne in mind that distribution delay The signal in the element is excluding or usually somewhat larger (about 1.5 times) than the delay in the simplest elements and, and non, or, or non.

Bit is a minimum unit of measurement of information, as it stores one of the two values \u200b\u200b- 0 (false) or 1 (TRUE). False and True translated into Russian lie and truth, respectively. That is, one bit cell can be simultaneously only in one state of the possible two. Let me remind you, the two possible states of the bitch cell are equal - 1 and 0.
There are certain operations for manipulations with bits. These operations are called logical or boolean operations, named after one of the mathematicians - George Bul (1815-1864), which contributed to the development of this area of \u200b\u200bscience.
All these operations can be applied to any bit, regardless of which it matches - 0 (zero) or 1 (one). Below are the main logical operations and examples of their use.

Logic operation and (and)

Designation and: &

Logical operation and is performed with two bits, let's call them a and b. The result of the logical operation and will be equal to 1, if A and B are equal to 1, and in all other (other) cases, the result will be equal to 0. We look at the truth table of the logical operation and.

a (bit 1) b (bit 2) a (bit 1) & B (bit 2)
0 0 0
0 1 0
1 0 0
1 1 1

Logic Operation or (OR)

Or: |

Logical operation or executed with two bits (A and B). The result of the execution of a logical operation or will be 0 if A and B are equal to 0 (zero), and in all other (other) cases, the result is 1 (unit). We look at the truth table of the logical Operation OR.

a (bit 1) b (bit 2) a (bit 1) | B (bit 2)
0 0 0
0 1 1
1 0 1
1 1 1

Logical operation excluding or (XOR).

Designation XOR: ^
The logical operation is excluding or executed with two bits (A and B). The result of an XOR logic operation will be equal to 1 (unit), if one of the bits A or B is 1 (unit), in all other cases, the result is 0 (zero). We look at the truth table of the logical operation excluding or.

a (bit 1) b (bit 2) a (bit 1) ^ b (bit 2)
0 0 0
0 1 1
1 0 1
1 1 0

Logical operation not (not)

Notation Not: ~
The logical operation is not performed with one bit. The result of the execution of this logical operation directly depends on the state of the bit. If the bit was in a zero state, the result of the NOT execution will be equal to one and vice versa. We look at the truth table of the logical operation.

a (bit 1) ~ A (bits denial)
0 1
1 0

Remember these 4 logical operations. Using these logical operations, we can get any possible result. Details about the use of logical operations in C ++ read.

In this article we will talk about some bit operations. Consider the main ones: xor (excluding or), and (and), not (no) as well as or (or).

As is known, the minimum unit of measurement of information is bitwhich stores one of the 2 values: 0 ( False, lies) or 1 ( True., truth). Thus, the bit cell can simultaneously be only in one of the two possible states.

For manipulations with bits, certain operations are used - logic or Boolean. They can be applied to any bit, regardless of what its value is zero or a unit. Well, let's look at the examples of using three basic logical operations.

Logic operation and (and)

And. denotes sign &.

The and operator is performed with 2 bits, we take, for example, a and b. The result of the operation of operation and is equal to 1, if A and B are equal to 1. In other cases, the result is 0. For example, with the help and you can find out, a self-number or not.

Look at the truth table and:

Logic Operation OR (or)

Denotes sign | .

Operator Or. Also performed with 2 bits (A and B). The result is 0, if a and b are equal to 0, otherwise it is equal to 1. We look at the truth table.

Logic Operation XOR (excluding or)

The XOR statement is denoted ^.

Xor. Performed with 2 bits (A and B). The result of the operation of the XOR operation ( excluding or) Equal to 1, when one of the bits b or a is 1. In other situations, the result of using an XOR statement is 0.

The truth table of the logical operation for XOR (excluding or) looks like this:

Using XOR (exclusive or), you can change the values \u200b\u200bof 2 variable identical data type, without using a temporary variable. And also, by XOR, you can encrypt text, for example:

String MSG \u003d "This Is a Message"; Char Message \u003d MSG.Tocararray (); String Key \u003d ". *)"; String EncryptedString \u003d New String (); for (int i \u003d 0; i< message.length; i++){ encryptedString += message[i]^key.toCharArray(); }

I agree, XOR is far from the most reliable encryption method, but this does not mean that it cannot be made part of a encryption algorithm.

NOT logical operation (not)

It is a batch denial, therefore it is performed with one bit and is denoted ~.

The result depends on the status of the bit. If it is in a zero state, the result of the operation is a unit and vice versa. Everything is extremely simple.

These 4 logical operations should be remembered primarily, because with their help you can get almost any possible result. There are also operations such as<< (побитовый сдвиг влево) и >\u003e (bitwise shift to the right).

The XOR command in the assembler performs an exception or between all bits of two operands. The result of the XOR operation is recorded in the first operand. Syntax:

XOR receiver, source

The XOR statement always drops CF and OF, as well as (depending on the result) changes the Flags SF, ZF and PF. The value of the AF flag can be any - it does not depend on the result of the operation.

The receiver can be one of the following:

  • Memory Area (MEM)

The source may be one of the following:

  • Memory Area (MEM)
  • General Purpose Register (REG)
  • Direct Value - Constant (IMM)

Taking into account the restrictions that were described above, the combination of the source receiver may be as follows:

REG, MEM MEM, REG REG, REG MEM, IMM REG, IMM

Operation of excluding or

When executing an exclusive or value value, it will be equal to 1 if the bits are compared (not equal). If the bits compared are the same value, the result will be equal to 0.

Therefore, this operation is called exclusive. It eliminates the same bits from comparison, and with unequal operations operation.

But, since any pair of unequal bits is 0 and 1, then the operation of the logical or as a result will give 1.

Tatac of the truth of excluding or

The truth table is below:

0 xor 0 \u003d 0 xor 1 = 1 1 XOR 0 \u003d. 1 1 Xor. 1 = 0

Features of the XOR operation

The XOR operation has a reversibility property. If you perform twice with the same operand twice, then the value value is inverted. That is, if you fulfill this operation between the bits X. and Y., ultimately we get the initial batch value H..

0 Xor. 0 \u003d 0 xor 0 = 0 0 Xor. 1 \u003d 1 xor. 1 = 0 1 Xor. 0 \u003d 1 xor. 0 = 1 1 Xor. 1 \u003d 0 xor 1 = 1

This property can be used, for example, for the simplest data encryption (this is somehow another).

Checking the Flag After XOR Operation

The XOR command works with 8-, 16- and 32-bit operations.

Sometimes there is a need to check the Flag of PF after performing the operation, in order to find out how many unit bits (even odd) are contained in junior Bay Result (This is necessary not only if the XOR operation is performed, but also when performing other arithmetic and logical operations).

If the flag is installed, then the result is a clear number of single bits. Otherwise, the flag will be reset.

You can also simply verify any number, without changing the value of the result. To do this, you need to execute the XOR command with zero value. That is, the receiver must be a verifiable number, and the source should be zero. And then you need to check the flag of the belief. Example:

Al, 10110101B; Place in Al a number with odd; number of single bits (5) Xor Al, 0; At the same time, the Flag of the PF is not; set (PO) MOV AL, 10110111B; Place in Al the number with a reader; the number of single bits (6 ) Xor Al, 0; In this case, the Flag of the PF; will be set (PE)

In debuggers, it is usually used to designate a number of units in the resulting result, and the PARITY EVEN reduction is used, and for odd - PO (Parity ODD).

Ready in 16-bit words

As already mentioned, the belief flag is set depending on the number of units contained in the younger results. To check the 16-bit operand reader, you need to execute the XOR command between the senior and the youngest byte of this number:

MOV AX, 64C1H; 0110 0100 1100 0001 - 6 single bits XOR AH, Al; flag of readiness will be installed

In such a simple way, the 16-bit operand is divided into two bytes (2 groups of 8 bits), and when executing the XOR command, single bits that are in the corresponding discharges of two 8-bit operands will not be taken into account. Because the corresponding bit of the result is zero.

The XOR command removes any intersecting unit bits of two 8-bit operands from the result and adds inversely single bits to the result. That is, the readiness of the 8-bit number received by us will be the same as the readiness of the original 16-bit number.

0110 0100 1100 0001 - Source 16-bit number 0 Xor. 1 = 1 1 Xor. 1 = 0 1 Xor. 0 = 1 0 Xor. 0 = 0 0 Xor. 0 = 0 1 Xor. 0 = 1 0 Xor. 0 = 0 0 Xor. 1 = 1

As a result, 4 units, that is, the PF flag will be installed

Ready in 32-bit dual words

Well, if you need to determine the readiness in a 32-bit number?

Then the number is divided into four bytes, and it is alternately with these bytes, an operation is performed or.

For example, we broke a 32-bit number B. Four byte B0., B1., B2., B3.where B0. - It is a younger byte.

Then to determine the readiness of the number in we will need to use the following formula:

B0 XOR B1 XOR B2 XOR B3

But in the assembler, such a record is unacceptable. Therefore, you have to think a little.

And finally, the origin of the mnemonics Xor.. There is a word E in English X.cEPTION - Exception. Reduction from this word is the letter H. (So \u200b\u200bit was necessary). You probably met such in advertising or in the names of products whose manufacturers claim (well, or think that claim) to exclusivity. For example, Lada Xray, Sony Xperia, etc. So XOR is an abbreviation collected from two words - E X.cEPTION Or. - excluding or.