XOR

DCCWiki, a community DCC encyclopedia.
Jump to: navigation, search
Short Definition
Logical function used for error checking.

The XOR Function

An XOR is a Boolean Algebra function. Mathematically, it performs addition of the inputs.

The term means Exclusive OR. It performs addition only when the inputs are in different states. Since the term OR is ambiguous when both inputs are the same, the Exclusive OR excludes that situtation.

XOR Truth Table

A two input XOR gate will have the following truth table:

Input A Input B Output Q
0 0 0
1 0 1
0 1 1
1 1 0

As the truth table shows, it can be one or the other but not both. An XNOR gate would have the output inverted. Logic gates can also have multiple inputs, but the result would still be the same.

Application

ANSI XOR Symbol

When the command station creates a digital packet, it takes the address and instruction bytes and performs an XOR operation on them. If the packet contains more than two bytes, it continues the process by XORing each subsequent byte with the result so far. The resulting byte is appended to the packet, which is then sent to the booster and on to the track.

For example, if the operation is performed on two numbers, such as 200 and 120, the result would be 176. (200 ⊕ 120 = 176)

Upon receipt of a packet, the decoder again takes the address and instruction bytes and XORs all of them. The result must be the same as the error detection byte, so if the decoder does a logical operation on all of the bytes which does not result in the correct answer, the packet is discarded and the decoder awaits the next one.

Since the environment that DCC works in can be very noisy electrically, this is a simple but effective means of detecting a packet which has become corrupted.

Further Reading

Exclusive OR at Wikipedia