Computer. In fact, the machine will be wrong. Data encoding for error checking and correction

Source: Internet
Author: User

    • Friday Java layout of the experiment wrote a day,,, heart very tired
    • Saturday morning volunteer activities led to sleep one afternoon evening to see the performance,,, heart tired
    • Later found that my C-dollar rose a lot,,, surprised,,, because I wrote the reason for the blog? ,,, Happy ~
    • Error checking and correction is really a very important part of a computer's processing, storing, and transmitting information.
    • What is the use of data that is handled incorrectly, even when the computer is powerful?
    • Even if you try again, the direction is wrong, in the end is not an empty
    • Even if it is human, it will inevitably make mistakes. Think of a distant story, that counted the wrong decimal point and suicide advance to heaven occupy the seat of the mathematician,,,,,, but it seems that suicide can not go to heaven? I don't know much,,,,,,
    • The so-called error, that is, the computer in the 1 and 0 of the binary data, some or some of the bit under the influence of a change, such as the original "0001" the second bit by some mysterious influence, resulting in the data into a "0011", natural is a big mistake.
    • Some of the mysterious effects include
      • Electromagnetic interference, radiation, vibration,,,,,,
      • Aging, damage to the device,,,,,,
Parity Check Code
  • The most common thought in analyzing a problem is to start with the simplest case
  • The principle of parity code:
    • Set a bit more (check bit) to record a binary data that is a string of 01 contains 1 of the number of parity
    • According to different realization ways, divided into odd test and even test
  • Odd Test Odd Parity
    • The test bit is 1, which means that the number of 1 in the data (not including the test bit) is an even number, plus the test bit is the "odd", is the so-called odd test
    • The test bit is 0, indicating that the data (not including the test bit) in the number of 1 is an odd number, it is already odd, then do not need to check the position of the help, check the position to take 0 is good
  • Even test even Parity
    • And the odd test is relatively called.
  • How do you calculate it? Remember the magic of the XOR operation?
    • Two numbers to make an XOR or operation
      • Same as 0
      • The difference is 1
    • and n number do XOR or operation
      • If the n number has an odd number of 1, the result is 1
      • If there is an even number of 1 in the n number, the result is 0
    • Different or Dafa is good, you can get the parity.
  • Why is this rule?
    • Intuitively we think that the test bit of the odd test is 1, 1 is true, that is, the data "really has an odd number of 1"
    • But in the actual coding, the test bit also belongs to the data ah ! Therefore, the test bit of the odd test is the meaning of the "true" represented by 1, that is, all data bits include the number of 1 in the test bit as odd number.
    • This is also convenient for computer implementation, and do not need to separate the test bit out, only need to specify in advance we use the odd test or even test can be.
      • For the odd test, we do an XOR operation with all the data including the test bit, and if the result is 1 we think the data is not wrong, otherwise we think the data is wrong.
      • For even tests, the result of an XOR together should be 0 before the data is considered to be error-free.
  • However, parity can only find "odd number of bits of error", because "odd" to affect the original parity
  • But because the implementation is simple, and in fact a small percentage of errors are just a bit of error, so parity application is very extensive
    • But after all, parity's testing ability is too low, and can only "test" and not "error correction", in the field of higher data accuracy requirements, parity obviously not enough to support the table

    • Gray (Marcel Golay) in 1949, Hamming (Richar Hamming) in 1950, respectively, the design of an error-correcting ability of the code. It was later called the sea-plaintext.

    • Based on the concept of minimum code distance in the theory of information coding, the minimum code distance of sea-codes is 3, which has the ability to check and correct one error and detect two-bit errors.
      • Minimum code spacing: In a set of coding systems, any valid encoding becomes the minimum number of bits that must be changed by another valid encoding.
      • If the minimum code distance of parity is 2, this is because the minimum need to change two bits can not change the original number of the parity of 1, thereby passing the parity.
About the Hamming code
    • The sea-light has a plurality of test bits, the exact number of which must be calculated according to the length of the original data.
    • And the multiple test bits are mixed with the data bits, but there are rules to follow.

    • The encoding bit setting number starts with 1, which is recorded as B1, B2, B3 ... Words

      • Inspection bit: All bits numbered 2^n are test bits, i.e. B1, B2, B4, B8 ... For the test bit, we put the inspection bit separately called C1, C2, C3, C4 ...
        • Then there are: Ci = B (2^i-1)
      • Data bits: Store the actual data, in addition to the test bit in order to store, separately encoded as D1, D2, D3, D4 .....
      • Because it is binary, this coding scheme actually has a more obvious rule in binary.
    • Look at the table. I especially like the grammar of markdown, especially the form
coded bit B1 B2 B3 B4 B5 B6 B7 B8 ...
Binary numbering 0001 0010 0011 0100 0101 0110 0111 1000 ...
corresponding meanings P1 P2 D1 P3 D2 D3 D4 P4 ...
Inspection bit P1 P2 P3 P4 ...
Data bits D1 D2 D3 D4 ...
    • It's a very aesthetic rule.
      • The coded bit for the test bit Pi is Bj, and the binary code with J has only the first I bit of 1
        • P1, corresponding to 2^0=1, corresponding to B1, that is, "0001" is only 1th bit 1
        • P2, corresponding to 2^1=2, corresponding to B2, that is, "0010" is only 2nd for 1
        • P3, corresponding to 2^2=4, corresponding to B4, that is, "0100" is only 3rd bit 1
        • P4, corresponding to 2^3=8, corresponding to B8, that is, "1000" is only 4th bit 1
The coding method of sea-plaintext
  • The specific coding method
    • data bits D1, D2, D3, D4 ... The original data is stored
    • here's how to get the test bit:
      • The data bits that are responsible for each test bit
        • p1:b1, B3, B5, B7 ...
        • p2:b2, B3, B6, B7 ...
        • p3:b4, B5, B6, B7 ...
        • P4:b8, B9, B10, B11 ...
      • Look at the above is probably hard to see what the law, but we put Bj's J into binary, then there is a very beautiful law.
        • p1:b0001, B0011, B01 01, B0111 ...
        • p2:b0010, B0011, B0110, B0111 ...
        • p3:b0100, B0101, B0110, B0111 ...
        • p4:b1000, B1001, B1010, B1011 ...
      • When when, the law is
        • Pi is responsible for all Bj, whose J's binary encoded the I bit is 1
        • that is, for any one Bj, if J's binary code of the first I Bit is 1, then BJ will be responsible for the Pi.
      • Obviously, a BJ may have more than 1, then this one BJ naturally corresponds to a number of responsible test bits
        • for the test bit, because the test bit corresponds to Bj's J binary has and only one Bit is 1, so the test bit is actually only responsible for itself
        • for the data bit, because the corresponding BJ's J binary must have more than 2 bits 1 (because only 1 bits 1 is necessarily the test bit), so A data bit is the responsibility of at least two test bits.
      • After the code bits that are responsible for each test bit are set, what about inspection bits? very simple, that is parity
coded bit B1 B2 B3 B4 B5 B6 B7 B8 ...
Binary numbering 0001 0010 0011 0100 0101 0110 0111 1000 ...
corresponding meanings P1 P2 D1 P3 D2 D3 D4 P4 ...
Responsible for the relationship P1 P1 D1 D2 D4 ...
Responsible for the relationship P2 P2 D1 D3 D4 ...
Responsible for the relationship P3 P3 D2 D3 D4 ...
Responsible for the relationship P4 P4 ...
How to use the sea-plaintext
  • So how do we look at thiscoding under the law of AestheticsIt? How to test errors and error correction under this coding scheme?
    • We say that the 1-bit test and error correction capability, and 2-bit test capability
    • error for 1-bit
      • if it is a check bit, the responsible relationship for the test bit will not pass parity
      • if the data bit, then the data bit corresponding to the multiple responsible relationship will not pass parity
      • then for all responsible relationships, we generate a binary number according to the order in which it is responsible for the inspection bit, that is, if the responsible relationship where Pi is located is not parity, then the first bit of the generated binary number is 1, Otherwise 0
      • the magic happened. The number we finally came up with is just the right one for the wrong person
        • If there is an error in the verification bit, and we specify that the location of the test bit pi is B (2^i-1), that is, the position of the Pi Bj, the binary encoding of J has and only the first I bit is 1, that is, pi is wrong, and the pi position is exactly "binary encoding There is only a position where the I-bit is 1 ". The correspondence is not wonderful.
        • If there is an error in the data bit, and we find that the bits of the encoded bit Bj, its J always contains a number of 1 bits, for each of the 1 of the first bit is a pi, then in the test, it will inevitably lead to these multiple responsible relationship Pi pass parity, and then generate the binary Digital coding is like "Light path reversible" general, just say that each of the first bit is set to 1, it is just the wrong position of the data bits. More wonderful.
      • for that matter, the code is one of the best-used structures I've ever seen for binary rules.
    • For 2-bit errors, the last number is still generated according to the above rules, but at this point it is not possible to determine which one is the error, but the generation is the number is not always 0.
      • Contradiction If a two-bit error occurs, the number generated is 0. BX and by errors
      • 1, if BX for the test bit , set bx corresponding test bit for Pi, because the final figure of 0, which requires responsible for the relationship Pi can pass parity, and parity the minimum code distance for 2,PI itself has been wrong, so responsible for the relationship pi must have a code to error, This bit can only be a data bit, that is, by only data bits . By if it is a data bit, then by must correspond to more than two responsible relations , in addition to responsible for the relationship pi, set up a second for the relationship PJ, is responsible for the relationship PJ has and only by the corresponding data bit error, so responsible for the relationship PJ must pass parity , so the generated number must not be 0. Contradiction.
      • 2, if Bx and by are the test bit, by 1 of the analysis of the Impossible . If the BX and by are both test bits, then the corresponding two responsible for the relationship Pi and Pj, the resulting number is necessarily not 0.
      • 3, if BX and by are data bits , BX and by is bound to correspond to more than two responsible relations . Since each responsible relationship is parity, the minimum code distance of 2, which requires all the BX and by involved in the responsible relationship need to include BX and by to ensure that through parity , so Bx and by is necessarily the same encoding bit. Contradiction.
    • For errors of more than 3 bits, the number generated could be 0. This is the same as the last generated number with the correct data . such as B3, B5 and B6. In other words, we need to change three bits at least, so we can get another code that is valid under the rules of the sea. So the minimum code distance is 3.
  • The actual use of the time
    • For a common 1-bit error, if we find a test bit error, but the actual test bit error does not affect the data bit, that is, the actual data is correct, it does not affect the transmission of data, you can not need to correct.
    • For a 2-bit error, we can only judge "wrong". In fact, however, we are not sure whether this is a mistake or a two-bit error.
      • If the accuracy requirements are not so high, the default error is usually 1-bit error, and based on whether the test bit to determine whether the need to correct.
      • If the requirement is high, then the "once error" will require the data to be resent.
    • For 3-bit and above errors, part of the error can be detected, only a few cases, and the probability of this situation is very small, will be "mixed with the sea-check."
Cyclic redundancy Check Code
    • CRC code. Cyclic redundancy Check.
    • One of the most common error checking codes in the field of data communication
    • The length of the information field and the Check field can be arbitrarily selected, relative to the rigid structure of the Yu Haiming code, because the use of more flexible mathematical knowledge, so the CRC is very flexible in terms of length
    • Because not within the scope of the test, although I have studied with interest, however, in the process of extremely painful, although the use of a lot of mathematical terminology, but did not let me feel the beauty of mathematics, so it is not intended to be here to let everyone see the pain so I myself also uncomfortable ...
    • Interested can self Google Baidu.
Internet Checksum
    • An encoding that is found when querying related content.
    • Not to do the introduction is only recorded there is a way to become
    • If you turn to this note later, if you are still interested, you can Google Baidu
    • Feel this blog a bit of water,,,,,, but I mainly want to talk about the sea-clear, and there is no suitable supporting things to say
    • Then I want to sort out the code, like ASCII, Unicode, UFT, which is not just one or two pages on the textbook ... It is troublesome and the exam is not tested, but the individual is very interested.
    • Later on the content of the processor, as well as the concept of instruction flow, optimization, scheduling algorithm and so on, even beyond the computer composition principle of the scope, because I also want to talk about the architecture of the content, especially the instruction dynamic scheduling algorithm.

Computer. In fact, the machine will be wrong. Data encoding for error checking and correction

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.