2.1.5 check code (with a text analysis you get to know: parity, Hamming code, CRC code)


What is a checksum?

  • Checksum: refers to 发现or capable of 自动纠正错误encoding the data, also known as the error detection correction code.
  • The principle: by plus one 冗余码, to test or error correction coding
  • Code distance: two binary numbers is simply compared in the same digit place, digit number of different values ​​how many, that is code distance, also known as the Hamming distance;
  • Yards from the two methods. Such as 0100 and 1111
    直接观察法: As can be seen, the number of different bit values 3, the code distance is 3.
    异或计算法: 0100⊕1111 = 1011, 1011 as a result, there are several different number 1 represents the number of bit values, i.e., the code distance What is, is 3 yards from here.

Why should check code?

  • In fact, from what is the check code, you can see why we need time to check code in the computer operation process, all data is stored in binary, arithmetic processing data transfer in the computer, we want the data processing, why should we working? Is to prevent the transmission factors due to other aspects of the hardware results in a change in the data, when we add redundancy bits of data processing, the original data becomes a checksum code, we can pass some of the corresponding checksum approach to 检测和纠正error, to ensure the accuracy of the data.

1. parity

  • The principle: adding a parity bit in the original code, then 原编码就变成了校验码it's a code distance of 2, can be surprisingly check bit error, but can not check out the even bit errors, increased redundancy is parity bits, checksum bits set in the far left or the far right of the original code.
  • Odd parity code: the entire check code (information bits + parity bit) in bit number 1 of the odd
  • Even parity for: the entire check code (information bits + parity bit) in bit number 1 of the even

Determine how the data is right or wrong it through parity?

  • First, in the computer, we have a good agreement, data is the use of odd parity or even parity, the following points odd and even parity to explain how parity checking whether the transmission of data in a computer process the data correctly.

(1) Odd parity

  • We assume that the original code is 10110111, because we require the use of a computer 奇校验, so we pay more at the far left of the original encoding a parity bit, and set to 1, then the original code becomes odd parity code, there is an odd number (7) 1 .
  • 传输过程中奇数个数据改变: There during transmission 奇数个数位值发生了改变, then we pass 奇校验运算can be found now become a 6 1, odd parity codes and a 3-digit value has changed compared to the odd code has an odd number no 1, but 1 becomes an even number, based on our data changed, an error can be checked.
  • 传输过程中有偶数个数据改变: During transmission there is 偶数个数位值发生了改变, then we pass 奇校验运算, we can find now become a 7 1, and the original odd parity code 7 as 1, is odd, then we can not determine whether the data through odd parity operation occurred the 即无法检查出偶数个错误change .
    Here Insert Picture Description

(2) even parity

  • We assume that the original code is 10110111, because we require the use of a computer 偶校验, so we added an extra parity bit in the original coding far left, and set to 0, then the original code becomes even parity, there is an even number (6) 1 .
  • 传输过程中奇数个数据改变: There during transmission 奇数个数位值发生了改变, then we pass 偶校验运算can be found now become a five, and even compared with a checksum value 3 digits has changed, there is no longer even parity even number 1, but 1 becomes an odd number, based on our data changed, an error can be checked.
  • 传输过程中有偶数个数据改变: During transmission there is 偶数个数位值发生了改变, then we pass 偶校验运算, can see now turned into a 6 1, and even the original checksum 6 as 1, are even, then we will not be judged by whether the data has even parity calculation the 即无法检查出偶数个错误change .
    Here Insert Picture Description

Why not check out an even number of errors?

  • By the above-described two methods parity check data can be obtained comparing the odd parity errors can be detected and can not check an even number of errors can not correct the error, the error can not locate the position.

2. Hamming (Hamming) check code

What is the Hamming check code?

  • A multi-code parity.
  • The principle: several check bits added to the information in the valid bit Hamming code is formed, and the bit assigned to each parity group number in the Hamming code. When a bit error will cause the value of the parity bit about a few changes.
  • Features: You can find the error, locate the error position, automatically correct the error. 可以检测多位错误,但只能纠正一位出错.

Correction Theory: L-1 = D + C and D≥C
encoding minimum code distance L, the larger the error detecting bits D, C correct errors greater number of bits, and error correction capability is less than a constant subject wrong capacity

Get to know a title Hamming code, the information bits n = 4, k = 3 parity bits, Hamming code 1010 seeking.

(1) determining the Hamming code bits

  • According to the formula: 2 k ≥ + the n-k + 1 (two to detect wrong, you need to add a parity bit, that bit k + 1)
    this formula in mind on the line, just as Einstein's theory of relativity do not know formula MC = E 2 the same.
    Hamming code bits n + k = 7, Equation 2 . 3 ≥ n-K + + =. 8. 1 established, n, k effective. Setting variables to represent the information bits, parity bits, Hamming code. As shown in FIG.
    Here Insert Picture Description

(2) determining parity bits P I position Hamming codes

  • Predetermined parity bit P I 2 bit Hamming bit number i-1 position, so that:
    Here Insert Picture Description

(3) Relationship between the packet checksum is formed

  • Each of the plurality of data bits with check bits to test.
  • Conditions must be met: 被校验数据位的海明码位号 = 校验该数据位的各校验位海明位号之和such check D3, its Hamming H6 bit number 6, then checking its parity bit P2 and P3, because their Hamming bit numbers add up to 6 H2 and H4.
  • Parity check bits do not need to be
  • Packet relationship is shown:
    Here Insert Picture Description

(4) parity bits P I value

  • P i values = all i-th group of data bits or divergent ⨁
  • P1=D1⨁D2⨁D4=0
  • P2=D1⨁D3⨁D4=1
  • P3=D2⨁D3⨁D4=0
  • Therefore, the Hamming code 1010:
    Here Insert Picture Description

    (5) the Hamming code check principle

    • Using each parity check bit groups he was involved in the formation of information bits and parity bits of the parity check, i.e., XOR operation ⨁, constituting k parity equations.
    • S1 = P1⨁D1⨁D2⨁D4
    • S2=P2⨁D1⨁D3⨁D4
    • S3 = P3⨁D2⨁D3⨁D4
    • If S1S2S3 = 000, then the error-free, or explain the error. This number is the value of the location of the error, such as S1S2S3 = 001, indicates a bit error, i.e. error H1, the direct inverse of the bit can achieve 纠错the purpose.

3. Cyclic Redundancy Check (CRC) code

What is the CRC?

  • The basic idea: a check code. Splicing R bit check bits after the K-bit information bits, the CRC code composed of such coding also known as (N, R) code
  • Features: You can find the error, locate the error position, automatically correct the error.可检测出所有奇数位错,所有双比特的错和所有小于、等于校验位长度的突发错
  • structure:
    Here Insert Picture Description

How original code CRC code generation code?

  1. First, the transmission end and the receiving end have a generator polynomial G (x) convention, the generator polynomial G (x) is the highest power R. Any available binary digital polynomial coefficients a 0 or 1 corresponding thereto. For example: binary number 1101 corresponding to G (X) = X-*. 1 . 3 +. 1 * X- 2 + * X-0 . 1 + X-. 1 * 0 = X- . 3 + X- 2 + 1'd
  2. In the K-bit binary information code to the left R-bit transmission terminal, to be transmitted, it generator polynomial G (x) corresponding to the binary number for 模2除法generating the remainder, to generate a R-bit check code together with the information code to form a new binary code (CRC) code, a total of K + R bits.

Modulo 2 arithmetic: modulo-2 addition divided, modulo-2 subtraction, multiplication modulo-2, modulo-2 addition, is not considered 进位, and 借位.

Question they get a CRC code generation and checking

Example: setting a generator polynomial G (X) = X- . 3 + X- 2 + 1'd, information code is 101001, find the corresponding CRC code.

  • Analysis: parity length: R = 3, the information code length: K = 6, CRC code length: N = R + K = 9
  • Binary code corresponding to the generator polynomial: 1101

(1) R-bit information symbols left

  • Sending the original information symbols left end position R, the low 0s: 101001 000

(2) modulo 2 division remainder obtained

  • Method: The information code shifted 101,001,000 divided by G (x) corresponding to the binary digital transmission terminal 1101 request the remainder, in addition to have enough remainder write 1, is not enough to write 0, until the remainder is less than 1101, the remainder is the checksum bit value.
  • Figure is the calculation steps to obtain the final result of the CRC code: 101001 001 , then the CRC code transmit side 101001 001 sent to the receiver.
    Here Insert Picture Description

(3) how to correct the error detection and error?

  • After the receiver receives the CRC, generated with a CRC code by the generator polynomial G (x) corresponding to the binary number, if the remainder is 0, then no error code information during transmission, the data correctly.
  • If the received CRC code C . 9 C . 8 C . 7 C . 6 C . 5 C . 4 C . 3 C 2 C . 1 = 101 001 011, divided by G (x) corresponding to the binary code 1101 to obtain a remainder of 010, it is not 0, indicating generating data errors during transmission. 2 = 010 (10) described C2 error, the C2 inverted to correct the error.
Published 36 original articles · won praise 5 · Views 3522

Guess you like

Origin blog.csdn.net/weixin_43914604/article/details/104183321